using ismember function in simulink
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Walter Roberson
am 3 Nov. 2018
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);
Siehe auch
Kategorien
Mehr zu Simulink Coder 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!