フィルターのクリア

How do I get ismember() to accept an unsorted vector in code within a MATLAB function block?

1 回表示 (過去 30 日間)
Nancy
Nancy 2014 年 12 月 20 日
回答済み: Nancy 2014 年 12 月 22 日
I'm trying to create a subsystem that returns the index of a given value within an array that is defined in the MATLAB workspace. When I input the vector to the MATLAB function block, I get an error message that the input vector is unsorted (with an arrow pointing to the call to ismember() in the code). But having an unsorted vector as the second operand is the point--I'm trying to get the index of a particular value in an unsorted vector.
So for example, in the attached models, if FiringOrder is defined in the MATLAB workspace as [1,4,2,6,3,5], I want to see 5 for y. (I've got two ways here of reading in the array, which seem to be equivalent--they both give the same error.) The code works without problem directly in MATLAB.
The exact error message is "Call to MATLAB function aborted: The second operand is not sorted in ascending order. Use SORT first.", with the arrow pointing to the line calling ismember().
I expect it's something simple--this is the first time I'm using the MATLAB function block. Can someone help me here? Thanks.
BTW, I'm running MATLAB R2014b.
  3 件のコメント
Nancy
Nancy 2014 年 12 月 20 日
Thanks Azzi -- I'm still learning this interface...
Nancy
Nancy 2014 年 12 月 21 日
I have the subsystem working now using find() instead of ismember(), but I would still like to know why the couple of lines of code that work in the MATLAB command window don't work when they are in a MATLAB function block, with an error message that doesn't seem related to the function block interface. If anybody can explain this to me, I'd appreciate it.

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

採用された回答

Nancy
Nancy 2014 年 12 月 22 日
Got the answer via a service request: ismember() is treated differently within a MATLAB function block because it's compiled into a MEX file, and one of the requirements for that is that the second argument be sorted in ascending order. That requirement is stated in this list: functions supported for code generation.

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by