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);