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

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

模型:

从信号来源的数据:

timeseries 数据:

Matlab 复制代码
sampleTime = 0.01;
numSteps = 1001;

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

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

simin = timeseries(data,time);

timetable 数据:

Matlab 复制代码
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域,否则不认出来。

Matlab 复制代码
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 数据:

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

Matlab 复制代码
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类型)里面包含关系

Matlab 复制代码
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里面的元素都是时间序列

Matlab 复制代码
% 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没有数据而已。

Matlab 复制代码
% 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数组。

Matlab 复制代码
% 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类型 | 无要求 | 是 | 是 |

注释:加载数组数据:

Matlab 复制代码
% 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);
相关推荐
2401_857439691 小时前
SSM 架构下 Vue 电脑测评系统:为电脑性能评估赋能
开发语言·php
孤亭远见2 小时前
COMSOL with Matlab
matlab
SoraLuna2 小时前
「Mac畅玩鸿蒙与硬件47」UI互动应用篇24 - 虚拟音乐控制台
开发语言·macos·ui·华为·harmonyos
xlsw_2 小时前
java全栈day20--Web后端实战(Mybatis基础2)
java·开发语言·mybatis
Dream_Snowar3 小时前
速通Python 第三节
开发语言·python
图南楠4 小时前
simulink离散传递函数得到差分方程并用C语言实现
matlab
高山我梦口香糖4 小时前
[react]searchParams转普通对象
开发语言·前端·javascript
信号处理学渣4 小时前
matlab画图,选择性显示legend标签
开发语言·matlab
红龙创客4 小时前
某狐畅游24校招-C++开发岗笔试(单选题)
开发语言·c++
jasmine s5 小时前
Pandas
开发语言·python