using ismember function in simulink
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello Guys,
Below you can see a very simple function I'm using in Simulink. When I try to run the simulation, the following error pops up (u1 and u2 are constants):
Function output 'Result' cannot be an mxArray in this context. Consider preinitializing the output variable with a known type.
Function 'MATLAB Function11' (#138.81.87), line 2, column 10:
"Result"
Any ideas??
Thanks.
function out = fcn(u1,u2)
coder.extrinsic('ismember');
Result=ismember(A,[u1 u2],'rows');
out=Result(Result==1);
댓글 수: 0
답변 (1개)
Walter Roberson
2018년 11월 3일
function out = fcn(u1,u2)
coder.extrinsic('ismember');
out = zeros(size(A, 1),1);
[~, out] = ismember(A,[u1 u2],'rows');
This version assumes that multiple rows might match, and assumes that you were looking for the index of the match, not a vector of logical true the length of the number of matches, empty for no match. If there is always definitely exactly one match then initialize out to 0.
If one match is what is expected then you should rewrite your code to avoid ismember since code cannot be generated for ismember.
Result = logical(size(A, 1),1);
Result = A(:, 1)==u1 & A(:, 2)==u2;
And then that convert that into the desired output, such as
out = 0;
out = find(Result, 1);
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!