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.
Best Answer