closest value to zero excluding the first one?
古いコメントを表示
If given a long vector of values. How can I find the index of the closest value to zero excluding the first value of the vector out of our list of stuff to search for
採用された回答
その他の回答 (2 件)
out of our list of stuff to search for
?
v = [-0.1 2 4 -0.5 8];
[~,i] = min(abs(v(2:end)))
v(i+1)
3 件のコメント
Image Analyst
2023 年 1 月 12 日
"out of our list of stuff to search for" <= He's searching FOR the index, so I think he really meant "out of our list of stuff to search", which is basically what @Torsten did. (No problem - non native English speakers probably don't know subtleties like that) The index would be
index = i+1;
Ali Almakhmari
2023 年 1 月 12 日
編集済み: Ali Almakhmari
2023 年 1 月 12 日
Ali Almakhmari
2023 年 1 月 12 日
Bora Eryilmaz
2023 年 1 月 12 日
編集済み: Bora Eryilmaz
2023 年 1 月 12 日
load('var.mat')
[~,I] = sort(abs(dis_y), 'ascend');
% Closest value to 0:
dis_y(I(1))
% Second closest value to 0:
dis_y(I(2))
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!