Compare arrays in Simulink

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

Friedrich
Friedrich 2013년 8월 14일
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?
Dhruv
Dhruv 2013년 8월 14일
편집: Dhruv 2013년 8월 14일
I actually need to be able to provide the range for the categorizing myself as they keep changing. I dont need something to round the values.
eg. A = [4.1,5.2,7.1]
Here,
*edit
0.0 < A <= 2.3 --- 1
2.3 < A <= 2.5 --- 2
2.5 < A <= 4.2 --- 3
4.2 < A <= 5.4 --- 4
5.4 < A <= 8.0 --- 5
Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 14일
This is not clear? what is 0-2.3 ?
Friedrich
Friedrich 2013년 8월 14일
편집: Friedrich 2013년 8월 14일
I guess thats the range. Values between 0 and 2.3 are mapped to 1 and so. However its not clear what hapens with values equal to 2.3. Are those values mapped to 1 or 2?
Dhruv
Dhruv 2013년 8월 14일
I have edited my comment to remove the confusion

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

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 14일

0 개 추천

A = [4.1,5.2,7.1];
B = [1,2,3,45,6,7,8];
out=zeros(size(B));
out(fix(A))=1

댓글 수: 10

Dhruv
Dhruv 2013년 8월 14일
I need to do this in Simulink without using any Matlab function blocks.
Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 14일
You have to explain, What are A and B? from constant blocks, or from what?
Dhruv
Dhruv 2013년 8월 14일
the arrays can be assumed to be from Constant blocks
PS. I have made a comment to the question to explain it better
Kaustubha Govind
Kaustubha Govind 2013년 8월 14일
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.
Friedrich
Friedrich 2013년 8월 14일
편집: Friedrich 2013년 8월 14일
@Kaustubha: AFAIK Dhruv is using TargetLink later which does not support the MATLAB Function block for code generation.
Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 14일
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.
Friedrich
Friedrich 2013년 8월 14일
편집: Friedrich 2013년 8월 14일
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
Dhruv 2013년 8월 14일
Yes, I am actually working with something similar to TargetLink called Intecrio. Sadly, I dont even have have a 'Custom Code Block' available to me.
Bottomline, I need to do this using Simulink. Any help is appreciated.
Friedrich
Friedrich 2013년 8월 14일
Is a Look-Up-Table supported? If so, this would be what you need together with a For Itterator Subystem.
Dhruv
Dhruv 2013년 8월 19일
I have the possibility of using a Matlab embedded block inside a Stateflow chart.. though I have never used Stateflow.. could you think of it as a possibility to be used in such a case?

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

Chetan Aswathanarayana
Chetan Aswathanarayana 2013년 8월 20일

0 개 추천

댓글 수: 1

Chetan Aswathanarayana
Chetan Aswathanarayana 2013년 8월 20일
https://www.dropbox.com/s/9iqv09tuw061vzj/Array_Compare.zip

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

카테고리

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

제품

질문:

2013년 8월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by