Find Nonzero element of a signal in simulink - without using "Find" block
20 views (last 30 days)
Show older comments
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!
Answers (2)
Azzi Abdelmalek
on 29 Aug 2016
Edited: Azzi Abdelmalek
on 29 Aug 2016
You can use compare to zero block

Peter Anderson
on 26 Apr 2018
Edited: Peter Anderson
on 26 Apr 2018
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.
0 Comments
See Also
Categories
Find more on Array and Matrix Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!