필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by