Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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 Kommentare
Nancy
Nancy am 21 Dez. 2014
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Nancy
Nancy am 22 Dez. 2014
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.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by