Correctly define the dimension for a timeseries of scalars
    조회 수: 9 (최근 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
      
 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
      
 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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

