Simulink: minimum values in vector segments

조회 수: 2 (최근 30일)
NiFu
NiFu 2020년 6월 30일
댓글: NiFu 2020년 7월 1일
In Simulink I have a vector, whose elements can be considered as groups. I need to find the minimum value of each group.
For example I have a vector of 20 elements, which can be devided in five segments of four elements each. The result should be a vector of five minimum values (one for each segment). The exact length of the vector and the number of segments are defined by workspace variables and are constant at runtime.
The equivalent matlab code would be this:
for segment = 1:n_segments
segment_length = n_input_elements/n_segments;
result(segment) = min( inputvector(1+(segment-1)*segment_length : 1+segment*segment_length) );
end
I did not manage to use the MinMax block (together with a selector block) to achieve the desired behaviour. Do you have any suggestions how to implement this?
Best regards

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2020년 6월 30일
편집: Fangjun Jiang 2020년 6월 30일
Use a MATLAB Function block and code similar like this: y=min(reshape(1:20,4,5))
work out the warnings and errors regarding variable size of the data
  댓글 수: 2
NiFu
NiFu 2020년 7월 1일
편집: NiFu 2020년 7월 1일
Thank you! The reshape function seems to be a good chioce, but I can't fix the errors. I specified the output size to the expected result length of reshape (in our example "5") and Simulink returns the following error message:
Data 'output' is inferred as a variable size matrix, while its properties in the Model Explorer specify its size as inherited or fixed. Please check the 'Variable Size' check box and specify the upper bounds in the size field.
I don't want to check "variable size", since I know the resulting data length of my function. In case I do, I get the following error message:
The signal at 'Input Port 1' of 'MinTest200630/Display' is a variable-size signal with a nondiscrete sample time. The sample time for any variable-size signal must be discrete.
How do I handle this properly?
NiFu
NiFu 2020년 7월 1일
Nevermind. Because of the poor performance of the matlab function block, I decided to go with two nested for iterator and assignment blocks. Thank you anyways!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by