Logical Indexing in Simulink

16 ビュー (過去 30 日間)
Femi Bolarinwa
Femi Bolarinwa 2020 年 12 月 21 日
コメント済み: Femi Bolarinwa 2020 年 12 月 24 日
I need guidance using logical indexing in a MATLAB function block in simulink. I simply want to select rows from the A matrix based on which elements of colomn one of the matrix is greater than a certain number. For example, input_matrix = [2 1 3; 1 4 2; 4 1 6], i want to use logical indexing to select rows of input_matrix where colomn 1 element is greater or equal to 2.
In matlab this would work just fine like this:
C = input_matrix(:,1) >= 2; %logical indexing of first colomn
output_matrix = input_matrix(C,:);
And output_matrix would be [2 1 3; 4 1 6];
However i get a variable size error when i put this in a MATLAB function block in simulink.
Thanks for your help.

採用された回答

Chaitanya Mallela
Chaitanya Mallela 2020 年 12 月 24 日
Hi Femi,
The output_matrix must be declared variable size while using this logical indexing in a MATLAB function block. When you double click MATLAB function block in Simulink, it opens MATLAB editor. On this editor tab, click edit data option thats edits data properties and manages ports. For the output_matrix, check the variable size checkbox and specify an explicit size in the size column (eg: [3,3]).
  3 件のコメント
Chaitanya Mallela
Chaitanya Mallela 2020 年 12 月 24 日
It is not necessary to specify exact dimensions, you can specify a numerical upperbound on the size to make Simulink realize a variable sized array.
Refer the documentation that demonstrates variable size declarations
Femi Bolarinwa
Femi Bolarinwa 2020 年 12 月 24 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSources についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by