How to find a value X of given Y close to 0, where the value X comes at the first place

3 ビュー (過去 30 日間)
Hi,
I used to solved my previous question to find a value X of given Y close to 0, but there is a value X comes from the very late place, which is not what I need. How can I extract the earlier value of X?
For example,
338.00 339.00 340.00 341.00 342.00 343.00 ... 964.00
1.00 -100.00 -100.00 -100.00 -100.00 -100.00 -100.00 ... -100.00
2.00 100.00 100.00 100.00 100.00 100.00 100.00 ... 100.00
3.00 0.28 0.12 -0.05 -0.21 -0.38 -0.55 ... -0.02
4.00 0.28 0.12 -0.05 -0.21 -0.38 -0.55 ... -0.02
5.00 8.21 8.24 8.26 8.28 8.30 8.32 ... 8.35
6.00 8.21 8.24 8.26 8.28 8.30 8.32 ... 8.35
Where the 340.00 is what I need, not the 964.00. How do I write the code to get 342.00?
The current code I am using is:
dr = damp_ratio(1:6 ,:);
[~,ix]=min(abs(dr),[],'all','linear');
[~,speed]=ind2sub(size(dr),ix);
Thanks in advance.
Terence

採用された回答

Matt J
Matt J 2021 年 1 月 19 日
編集済み: Matt J 2021 年 1 月 19 日
damp_ratio=[ -100.00 -100.00 -100.00 -100.00 -100.00 -100.00 -100.00
100.00 100.00 100.00 100.00 100.00 100.00 +100
0.28 0.12 -0.05 -0.21 -0.38 -0.55 -0.02
0.28 0.12 -0.05 -0.21 -0.38 -0.55 -0.02
8.21 8.24 8.26 8.28 8.30 8.32 8.35
8.21 8.24 8.26 8.28 8.30 8.32 8.35]
damp_ratio = 6×7
-100.0000 -100.0000 -100.0000 -100.0000 -100.0000 -100.0000 -100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 0.2800 0.1200 -0.0500 -0.2100 -0.3800 -0.5500 -0.0200 0.2800 0.1200 -0.0500 -0.2100 -0.3800 -0.5500 -0.0200 8.2100 8.2400 8.2600 8.2800 8.3000 8.3200 8.3500 8.2100 8.2400 8.2600 8.2800 8.3000 8.3200 8.3500
dr = diff( sign(damp_ratio(1:6 ,:)),1,2)~=0 ;
[val,ix]=max(dr,[],2);
speed=ix+1;
speed(val==0)=nan
speed = 6×1
NaN NaN 3 3 NaN NaN
  12 件のコメント
Matt J
Matt J 2021 年 1 月 21 日
編集済み: Matt J 2021 年 1 月 21 日
So I just wonder if there is a general way to get the first zero-crossing value in damp_ratio.
It is not obvious how you propose to define a unique "first zero-crossing" for a two-dimensional array. Zero-crossings and the order in which they occur are 1-dimensional concepts. You scan through a 1 dimensional list of numbers in order until the sign of the numbers changes. A two dimensional array of numbers has no ordering.
Matt J
Matt J 2021 年 1 月 21 日
Terrence's comment moved here.
Thanks for that comments. It seems that there is no way to achieve my goal in the current situation. :(

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by