error of min() function in matlab function block in simulink (v 2018b)

13 ビュー (過去 30 日間)
Andrea Valletta
Andrea Valletta 2020 年 10 月 30 日
コメント済み: Ameer Hamza 2020 年 10 月 31 日
Dear Matlab community,
I am trying to implement the minimum search within a matlab function block in a simulink model.
I need to find the minimum element and hence its coordinates of a matrix so I used the following code where the matrix "a" may contain 'nans'
>> [r,c]=find(a==min(a,[],'all'),1,'first')
however, I get the error " Invalid option. Option must be 'omitnan' or 'includenan' ". I substituted 'omitnan' to 'all' option but I eneded up with a "size mismatch" error.
So I am now using a for loop to search the minimum in the matrix, but this slows down my code.
I saw that this issue could arise with matlab releases that are older than 2018b, but I am using 2018b.
Do you know if there are other ways to solve this problem? Am I doing something wrong?
thank you in advance
Andrea

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 30 日
According to documentation, the 'all' option is not supported for code-generation in R2018b (i.e., it will not work in Simulink). Also, using find() with min() might be inefficient. Try following
[~, idx] = min(a(:));
[r, c] = ind2sub(size(a), idx)
  2 件のコメント
Andrea Valletta
Andrea Valletta 2020 年 10 月 30 日
Thank you so much, it worked fine
Ameer Hamza
Ameer Hamza 2020 年 10 月 31 日
I am glad to be of help!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by