Selected out to simulink

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.

 채택된 답변

cyberdyne
cyberdyne 2011년 2월 23일

0 개 추천

It's very very good!! Thank you very much.
Therefore if we suppose that we connect to emlblock two variable inputs with the same temporary variable (for example two definite integrals from t0 to t0+Ts for each of them, where t0 is starting istant and Ts is clock time), we can take out the equal element writing:
function y = fcn(u1,u2)
% This block supports the Embedded MATLAB subset.
% See the help menu for details.
eml.extrinsic('ismember')
eml.extrinsic('find')
a=ismember(u1,u2);
r=find(a);
rr=1;
rr=r;
ur=u1(rr);
y =ur;
is it???

댓글 수: 4

Paulo Silva
Paulo Silva 2011년 2월 23일
It's not that easy, try the function just like I did and after it's working try to change it for what you want, you will find several problems to solve because of the embedded function limitations.
cyberdyne
cyberdyne 2011년 2월 23일
I'll do it. Really thanks for the help!!!
Paulo Silva
Paulo Silva 2011년 2월 23일
Thank you too for selecting your own answer instead of mine!
cyberdyne
cyberdyne 2011년 2월 23일
Really I don't make this function necessarily with EML. I can do it with C S-function but I don't know C commands to make it.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Paulo Silva
Paulo Silva 2011년 2월 23일

1 개 추천

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

cyberdyne
cyberdyne 2011년 2월 23일
It says me that "find" is not supported by EML.
Guy Rouleau
Guy Rouleau 2011년 2월 24일
Find is supported only since a few releases, R2009b I think. It is not supported in previous releases.
cyberdyne
cyberdyne 2011년 2월 24일
Can i upgrade it with, for example, R2010? Or i've to uninstall old and reinstall R2010?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Communications Toolbox에 대해 자세히 알아보기

질문:

2011년 2월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by