Find Nonzero element of a signal in simulink - without using "Find" block
Mostra commenti meno recenti
Hi,
I need to find nonzero elements in Simulink of a Boolean vector signal, for example:
[1;0;1;0;0]
Basically it comes from comparison of two signals. This can be done by a find block in Simulink but I am only using blocks in the "slcilib" (simulink code inspector library) for code certifiable reasons, and of course it does not contain a find block.
What I expect to have is the index vector itself, in this case [1 3], and I will feed this index vector to a selector block index port (this port does not support Boolean data type!), to select corresponding values of another signal and assign these values.
Is it possible to do it using only math and logic operations that are contained in the slcilib? Any clue would be helpful!
Thanks!
4 Commenti
John D'Errico
il 29 Ago 2016
Modificato: John D'Errico
il 29 Ago 2016
You were asked to think about a problem. To look for the answer. By looking, you will learn about the tool.
If your teacher wanted you to be given the answer here, they would have given it to you, telling you to use a specific tool. So spend a few minutes and read the help. Look at what is available. And make an effort. You might learn something, and along the way, you might see some other tools in there that will help you in the future on some other problem.
Jiannan Zhang
il 29 Ago 2016
Azzi Abdelmalek
il 29 Ago 2016
@Jiannan, the community does not represent Mathworks, we almost have the same status, except some earned privileges to edit or delete questions! In this forum, we try to avoid answering homework, but sometimes it's not clear if it's an assignment or not. So, there is nothing funny about Jhon's comment
Jiannan Zhang
il 29 Ago 2016
Risposte (2)
Azzi Abdelmalek
il 29 Ago 2016
Modificato: Azzi Abdelmalek
il 29 Ago 2016
0 voti
You can use compare to zero block

3 Commenti
Jiannan Zhang
il 29 Ago 2016
Azzi Abdelmalek
il 29 Ago 2016
Modificato: Azzi Abdelmalek
il 29 Ago 2016
Edit
If yoursignal=[1 0 1 0 1 ], If the sample time is ts=0.1 for example to get the indices,
idx=10*ts*yoursignal=1*1=1
idx=10*2*ts*yoursignal=2*0=0
idx=10*3*ts*yoursignal=3*1=3
idx=10*4*ts*yoursignal=4*1=0
idx=10*5*ts*yoursignal=5*1=5
You get the indices 1,3 and 5. You will ignore the 0 value
NB: n*Ts is given by the clock
Jiannan Zhang
il 29 Ago 2016
Peter Anderson
il 26 Apr 2018
Modificato: Peter Anderson
il 26 Apr 2018
0 voti
See my answer to this question here:
Short answer is use a for-iterator subsystem. This version finds the first non-zero element and then stops looking.

Note that there will be a performance hit doing it this way over MATLAB function block with a find function call when simulating in normal mode. Not noticable for small arrays but I tested it for large arrays with a one in the final index and it was much slower. Running in accelerator mode was fine though.
Categorie
Scopri di più su Array and Matrix Mathematics 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!

