正确定义标量时间序列的维度

时间:2018-09-06 07:58:38

标签: matlab struct dimension bus

我想从Simulink中的mat文件中读取数据。为了创建数据文件和总线,我正在使用时间序列对象。

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

然后我想在Simulink中阅读它。因此,我有一个矩阵,一个向量和一个标量。我遇到的问题是标量的维数[1 1]不为1,因此Simulink将其视为矩阵/向量,而Simulink不允许我执行某些操作。所以我的问题是,如何将标量的尺寸固定为1而不是[1 1]。

Simulink file is here,在MATLAB Central中。首先运行上面的代码,然后运行Simulink文件。

编辑

我得到了一个答案,必须对数据进行压缩。

scalar_ts.Data = squeeze(scalar_ts.Data);

0 个答案:

没有答案