当前位置: 首页 > article >正文

Matlab模块From Workspace使用数据类型说明

Matlab原文连接:Load Data Using the From Workspace Block

模型:

从信号来源的数据:

timeseries 数据:

sampleTime = 0.01;
numSteps = 1001;

time = sampleTime*[0:(numSteps-1)];
time = time';

data = sin(2*pi/3*time);

simin = timeseries(data,time);

 timetable 数据:

sampleTime = 0.01;
numSteps = 1001;

time = sampleTime*[0:(numSteps-1)];
time = time';

data = sin(2*pi/3*time);

secs = seconds(time);
simin = timetable(secs,data);

struct 数据:

Struct的必须得有一个time域和Signals.values域,否则不认出来。

clear simin;

sampleTime = 0.01;
numSteps = 1001;

time = sampleTime*[0:(numSteps-1)];
time = time';

data = sin(2*pi/3*time);

simin.time = time;
simin.signals.values = data;

array 数据:

第一列必须是时间,第二列是数据。

sampleTime = 0.01;
numSteps = 1001;

time = sampleTime*[0:(numSteps-1)];
time = time';

data = sin(2*pi/3*time);

simin = [time,data];

加载Bus数据:

Bus 数据:下面是Bus元素定义和Bus(SinBus与SinsoldBus类型)里面包含关系

elems(1) = Simulink.BusElement; %必须有一个Simulink.Bus元素
elems(1).Name = 'Sine';% 必须得有元素名称
elems(2) = Simulink.BusElement;
elems(2).Name = 'BigSine';
SineBus = Simulink.Bus;%创建Bus,并将元素幅值给Bus元素。
SineBus.Elements = elems;

clear elems;
elems(1) = Simulink.BusElement; % 创建Bus数据类型
elems(1).Name = 'SineBus';
elems(1).DataType = 'Bus: SineBus';
elems(2) = Simulink.BusElement;
elems(2).Name = 'Cosine';
SinusoidBus = Simulink.Bus;
SinusoidBus.Elements = elems;

Bus里面的元素都是时间序列

% Create workspace data for bus
clear busin
sampleTime = 0.01;
numSteps = 1001;

time = sampleTime*[0:(numSteps-1)];
time = time';

data = sin(2*pi/3*time);
cosdata = cos(2*pi/3*time);
ampdata = 2*data;

busin.Cosine = timeseries(cosdata,time);
busin.SineBus.Sine = timeseries(data,time);
busin.SineBus.BigSine = timeseries(ampdata,time);

% Create Simulink.Bus object to define bus hierarchy
elems(1) = Simulink.BusElement;
elems(1).Name = 'Sine';
elems(2) = Simulink.BusElement;
elems(2).Name = 'BigSine';
SineBus = Simulink.Bus;
SineBus.Elements = elems;

clear elems;
elems(1) = Simulink.BusElement;
elems(1).Name = 'SineBus';
elems(1).DataType = 'Bus: SineBus';
elems(2) = Simulink.BusElement;
elems(2).Name = 'Cosine';
SinusoidBus = Simulink.Bus;
SinusoidBus.Elements = elems;

Partially specified 数据 : 和上面对比只是cosine没有数据而已。

% Create workspace data for bus
clear busin
sampleTime = 0.01;
numSteps = 1001;

time = sampleTime*[0:(numSteps-1)];
time = time';

data = sin(2*pi/3*time);
ampdata = 2*data;

clear busin
busin.Cosine = [];
busin.SineBus.Sine = timeseries(data,time);
busin.SineBus.BigSine = timeseries(ampdata,time);

% Create Simulink.Bus object to define bus hierarchy
elems(1) = Simulink.BusElement;
elems(1).Name = 'Sine';
elems(2) = Simulink.BusElement;
elems(2).Name = 'BigSine';
SineBus = Simulink.Bus;
SineBus.Elements = elems;

clear elems;
elems(1) = Simulink.BusElement;
elems(1).Name = 'SineBus';
elems(1).DataType = 'Bus: SineBus';
elems(2) = Simulink.BusElement;
elems(2).Name = 'Cosine';
SinusoidBus = Simulink.Bus;
SinusoidBus.Elements = elems;

array Buses 数据:

直接是一个Bus数组。

% Create workspace data for bus
sampleTime = 0.01;
numSteps = 1001;

time = sampleTime*[0:(numSteps-1)];
time = time';

data = sin(2*pi/3*time);
cosdata = cos(2*pi/3*time);
ampdata = 2*data;

bus1.Cosine = timeseries(cosdata,time);
bus1.SineBus.Sine = timeseries(data,time);
bus1.SineBus.BigSine = timeseries(ampdata,time);

bus2.Cosine = timeseries((cosdata-1),time);
bus2.SineBus.Sine = timeseries((data-1),time);
bus2.SineBus.BigSine = timeseries((ampdata-1),time);

busin = [bus1,bus2];

% Create Simulink.Bus object to define bus hierarchy
elems(1) = Simulink.BusElement;
elems(1).Name = 'Sine';
elems(2) = Simulink.BusElement;
elems(2).Name = 'BigSine';
SineBus = Simulink.Bus;
SineBus.Elements = elems;

clear elems;
elems(1) = Simulink.BusElement;
elems(1).Name = 'SineBus';
elems(1).DataType = 'Bus: SineBus';
elems(2) = Simulink.BusElement;
elems(2).Name = 'Cosine';
SinusoidBus = Simulink.Bus;
SinusoidBus.Elements = elems;

struct 和 Bus 区别和相同点:

数据类型类型fiel有要求timeseries可以多个
Struct不需要定义类型fiel必须是time与signals.values
Bus需要定义Bus类型无要求

注释:加载数组数据:

% Define simin variable for Signal From Workspace block
sampleTime = 0.01;
numSteps = 1001;

time = sampleTime*[0:(numSteps-1)];
time = time';

data = sin(2*pi/3*time);

simin = timeseries(data,time);

% Define bus object for Bus From Workspace block output data type
elems(1) = Simulink.BusElement;
elems(1).Name = 'Sine';
elems(2) = Simulink.BusElement;
elems(2).Name = 'BigSine';
SineBus = Simulink.Bus;
SineBus.Elements = elems;

clear elems;
elems(1) = Simulink.BusElement;
elems(1).Name = 'SineBus';
elems(1).DataType = 'Bus: SineBus';
elems(2) = Simulink.BusElement;
elems(2).Name = 'Cosine';
SinusoidBus = Simulink.Bus;
SinusoidBus.Elements = elems;

% Define bus data for busin variable
cosdata = cos(2*pi/3*time);
ampdata = 2*data;

clear busin;
busin.Cosine = timeseries(cosdata,time);
busin.SineBus.Sine = timeseries(data,time);
busin.SineBus.BigSine = timeseries(ampdata,time);


http://www.kler.cn/a/418192.html

相关文章:

  • hive3.1.3安装及基本例子
  • 1180 - 【入门】数字出现次数
  • C#VB.NET开发整体一键国际化显示
  • 互联网基础
  • 基于Python制作一个简易UI界面
  • 权限提升漏洞之Netlogon协议详解 以及可能出现得漏洞分析
  • leetcode 502.IPO
  • Synaplify之identify_debugger抓信号
  • 使用 Selenium 和 Python 爬取腾讯新闻:从基础到实践
  • SystemUI 下拉框 Build 版本信息去掉
  • LeetCode题练习与总结:找到字符串中所有字母异位词--438
  • 数据库日期时间用什么类型?
  • JMeter实时性能压测可视化系统整合
  • Linq(C#)之对数据分组
  • Springboot小知识(1):启动类与配置
  • Oracle--表空间Tablespace
  • 验证 kubelet 服务已经停止并且不再生成错误日志
  • 达梦数据库常用指令都是工作中常用的
  • 2024金盾信安杯线上赛 MISC ezpng[wp]
  • 【如何提升代码工程质量】code review篇
  • 【机器学习】机器学习学习笔记 - 数据预处理 - 01
  • C++(四)
  • 【系统架构设计师】高分论文:论分布式架构设计及其实现
  • 基于Java Springboot宠物咖微信小程序
  • 指针与字符串简单练习
  • 深入研究:Vue.js 响应式系统的原理与优化