Correctly define the dimension for a timeseries of scalars

10 次查看(过去 30 天)
I want to read data from a mat file in Simulink. To create the data file and the bus I am using timeseries objects.
dt = 0.1;
tend = 24;
t = 0:dt:24;
tk = size( t, 2 );
matrix_in = repmat( eye(3), 1, 1, tk );
scalar_in = t;
vector_in = randn( 3, tk );
vector_in_1 = vector_in;
vector_in_2 = vector_in;
vector_in_1( vector_in_1 <= 0.5 ) = 1;
vector_in_1( vector_in_1 > 0.5 ) = 0;
vector_in_2( vector_in_2 >= -0.5 ) = 1;
vector_in_2( vector_in_2 < -0.5 ) = 0;
vector_in = vector_in_1 + vector_in_2;
matrix_ts = timeseries( matrix_in, t, 'name', 'matrix_data' );
vector_ts = timeseries( vector_in, t, 'name', 'vector_data' );
scalar_ts = timeseries( scalar_in, t, 'name', 'scalar_data' );
matrix_ts = delsample( matrix_ts, 'Value', t( t >= 10 & t <= 15 ) );
vector_ts = delsample( vector_ts, 'Value', t( t >= 18 & t <= 20 ) );
scalar_ts = delsample( scalar_ts, 'Value', t( t >= 7 & t <= 11 ) );
data_struct = struct( 'matrix_in', matrix_ts, ...
'vector_in', vector_ts, ...
'scalar_in', scalar_ts );
save 'my_data' 'data_struct' -v7.3;
my_bus = Simulink.Bus.createObject( data_struct );
Then I want to read it in Simulink. So, I have a matrix a vector and a scalar, the problem I am having is that the scalar has dimension [1 1] not 1, and because of that Simulink treat it as a matrix/vector and Simulink does not allow me to do some operations. So my question is, how can I fix the dimension for the scalar to be 1 and not [1 1]. First run the code above and then the Simulink file.
  2 个评论
mbvoyager
mbvoyager 2018-9-6
I have no clue about Simulink.
But what I can see is that you are actually passing three objects of the type timeseries in a structure object. One single structure object is always represented as [1x1 objectclassname] is that your issue?
Or is your issue that
size(scalar_ts.Data)
returns
ans =
1 1 241
which is a a [1x1x241] matrix.
If so you could just do
scalar_ts.Data = squeeze(scalar_ts.Data);
to have a [1x241]

请先登录,再进行评论。

采纳的回答

mbvoyager
mbvoyager 2018-9-7
size(scalar_ts.Data)
returns
ans =
1 1 241
which is a a [1x1x241] matrix.
If so you could just do
scalar_ts.Data = squeeze(scalar_ts.Data);
to have a [1x241]
You are welcome. ;-)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by