How to get the index of the first non-zero element in an 1-D array in SIMULINK

Hi, guys
I want to find the index of the first non-zero element in a 1-D array in simulink, just like the way that 'find' command in matlab did.
For example:
x = [0 0 5 0 3 0];
idx = find(x~=0, 1, 'first');
The answer would be:
idx = 3.
So, how to do this in simulink?
Thanks!
by Ben

 採用された回答

Arnaud Miege
Arnaud Miege 2011 年 4 月 6 日

1 投票

Use the Find block.
HTH,
Arnaud

5 件のコメント

Benjamin Wang
Benjamin Wang 2011 年 4 月 6 日
Thank you Arnaud.
The problem is that the 'Find' block outputs a variable-size vector. I tried to index the output with 'selector', 'submatrix' and 'variable selector', but all failed. It says that these blocks don't accept variable-size vector as input.
Any solution to this?
Arnaud Miege
Arnaud Miege 2011 年 4 月 6 日
What do you want to use the index value for? If it is for indexing into the original vector (x)? If so, you can use the Selector block, but you need to set the Index option to "Index vector (port)". Then feed the output of the Find block to the "Idx" port and the original vector x to the "U" port.
If you really need the index value, you can feed the output of the Find block to a MinMax block set to Min. Since the index vector will be monotically increasing, the mininum will be the index of the first non-zero value.
HTH,
Arnaud
Benjamin Wang
Benjamin Wang 2011 年 4 月 6 日
The Minimum block works good. Thank you!
Hongmei Hu
Hongmei Hu 2011 年 5 月 31 日
HI, i had very similar problem.
I am doing the svd in Simulink, I got the eigenvalue, now I want to set some eigenvalues smaller than a given value to zero. for example, if the eigenvalue small than 2, i set it to zero and keep those eigen values large than 2 unchanged, incuding the place in the matix and the value.
PS: my matlab is 2009b, there are no Find block. so I can not use that block to find the zero value also.
br,
hongmei
Arnaud Miege
Arnaud Miege 2011 年 5 月 31 日
Not sure. Please create a new question with a meaningful title rather than append your question to an existing one, you're much more likely to get an answer, see:
http://www.mathworks.co.uk/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSimulink Functions についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by