How can I find an specific value inside an array without using the find function?

19 ビュー (過去 30 日間)
Pipe
Pipe 2022 年 8 月 28 日
コメント済み: Walter Roberson 2022 年 8 月 28 日
I need to store the index when w>=10 in an array without using the find function. So for example in my code w=10 at t1 8. Is there any way to do that without using the find function?
array=zeros(2,2);
t=0:20;
i=2;
dwdt = @(t,w)(-2.*w+5.05.*w.^0.6);
[t,w] = ode45(dwdt,t,0.5);
%w=10 @ t= 8
index= find(w>=10);%dont use find function
array(i)= index(1);
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 8 月 28 日
What is the reason to avoid find()? There are ways to get indices in a vectorized way without using find() but they are not especially efficient for large matrices.

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

採用された回答

Voss
Voss 2022 年 8 月 28 日
編集済み: Voss 2022 年 8 月 28 日
You can use the max function with second output argument, applied to the logical array w>=10, in order to return the first index where w>=10.
array=zeros(2,2);
t=0:20;
i=2;
dwdt = @(t,w)(-2.*w+5.05.*w.^0.6);
[t,w] = ode45(dwdt,t,0.5);
%w=10 @ t= 8
[~,index] = max(w>=10);
disp(index)
8
array(i)= index(1);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by