Selected out to simulink
Mostra commenti meno recenti
Hi,
I've two arrays
ARRAY1=[5 4 1]' ARRAY2=[6 5 9]'
I need an Embedded funcion in simulink which take out equal value element ONLY (for example 'out=5' only). Please help me.
Risposta accettata
Più risposte (1)
Paulo Silva
il 23 Feb 2011
Here's a code that works just for your example, I had trouble with mxArray not being supported by embedded functions so the final code looks very bad but works, I tested it with your arrays, each one inside a constant block, both array connect to a mux and that mux to the embedded function, the result is shown on a display, in this case the display shows the number 5
function y = fcn(u)
% This block supports the Embedded MATLAB subset.
% See the help menu for details.
eml.extrinsic('ismember')
eml.extrinsic('find')
u1=[u(1) u(2) u(3)]; %had to do this instead of u1=u(1:3)
u2=[u(4) u(5) u(6)];
a=ismember(u1,u2);
r=find(a);
rr=1; %the trick here is to have a temporary variable of the same type
rr=r; %we expect the extrinsic function to return
ur=u1(rr);
y =ur;
3 Commenti
cyberdyne
il 23 Feb 2011
Guy Rouleau
il 24 Feb 2011
Find is supported only since a few releases, R2009b I think. It is not supported in previous releases.
cyberdyne
il 24 Feb 2011
Categorie
Scopri di più su Communications Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!