Compare arrays in Simulink
Afficher commentaires plus anciens
I have two arrays which I would like to compare with each other.
eg. A = [4.1,5.2,7.1] B = [1,2,3,4,5,6,7,8]
I want to be able to say that the following match 4.1->4, 5.2->5, 7.1->7 and then show it in a different array like C = [0,0,0,1,1,1,0]
I have been trying to use For loops but havent managed to solve it as yet. Any suggestions would be useful
*edit
I cannot use a Matlab function block as I need to use it with TargetLink later.
Thanks, Dhruv
5 commentaires
Friedrich
le 14 Août 2013
What with a value of 5.8? Is this then equal to 6 or still to 5? Basically what kind of rounding do you apply?
Azzi Abdelmalek
le 14 Août 2013
This is not clear? what is 0-2.3 ?
Dhruv
le 14 Août 2013
Réponses (2)
Azzi Abdelmalek
le 14 Août 2013
A = [4.1,5.2,7.1];
B = [1,2,3,45,6,7,8];
out=zeros(size(B));
out(fix(A))=1
10 commentaires
Dhruv
le 14 Août 2013
Azzi Abdelmalek
le 14 Août 2013
You have to explain, What are A and B? from constant blocks, or from what?
Dhruv
le 14 Août 2013
Kaustubha Govind
le 14 Août 2013
Dhruv: This kind of problem seems more suited to MATLAB than Simulink - is there a reason you are opposed to using the MATLAB Function block? Note that you CAN generate C/C++ code from this block.
Azzi Abdelmalek
le 14 Août 2013
The simulink coder support the Matlab function block. some matlab function are not supported, but there is a way to do it without those functions.
Yes, SL Coder can handle MATLAB function blocks, but not TargetLink ;)
AFAIK TargetLink has its own block called "Custom Code block" which uses selfwritten C file. I guess implementing this in C is a way easier and faster (not in executing it, but faster in implementing that logic) than doing it in Simulink. Would that be an option for you?
In that way you could also write MATLAB code for that task, use the MATLAB Coder to generate C code from the MATLAB code and then use that C code in the custom code block.
Dhruv
le 14 Août 2013
Friedrich
le 14 Août 2013
Is a Look-Up-Table supported? If so, this would be what you need together with a For Itterator Subystem.
Dhruv
le 19 Août 2013
Chetan Aswathanarayana
le 20 Août 2013
0 votes
1 commentaire
Chetan Aswathanarayana
le 20 Août 2013
https://www.dropbox.com/s/9iqv09tuw061vzj/Array_Compare.zip
Catégories
En savoir plus sur Simulink Functions dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!