Index with min command
1 回表示 (過去 30 日間)
古いコメントを表示
Hi
I am working with the minimums calculated from two arrays in the following way -
NE = 100;
t = linspace(0,2,2*NE);
T = linspace(0,1,2*NE);
for ii = 1:NE
[val,index] = min(abs(t-T(ii)))
end
now i understand the value of "val", but i cannot figure out how the values for "index" are coming out. For my work the value of index is very important. I would really appreciate if someone help me figure it out.
Thanks
Hossain
2 件のコメント
回答 (2 件)
Azzi Abdelmalek
2012 年 11 月 18 日
編集済み: Azzi Abdelmalek
2012 年 11 月 18 日
NE = 100;
t = linspace(0,2,2*NE);
T = linspace(0,1,2*NE);
val=[];
index=[];
for ii = 1:NE
[val1,index1] = min(abs(t-T(ii)))
val=[val val1];
index=[index index1];
end
index is the position of the min value in the vector t
3 件のコメント
Azzi Abdelmalek
2012 年 11 月 18 日
編集済み: Azzi Abdelmalek
2012 年 11 月 18 日
It's clear min value don't belong to t, it's the position of the value of t making t-T(ii) minimal. And I did'nt say it's a minimal value of t
Jan
2012 年 11 月 19 日
編集済み: Jan
2012 年 11 月 19 日
Ok, then I confuse "index is the position of the min value in the vector t" with "...of the vector t". My English is not firm.
The problem of the OP is exactly, that the meaning of the index is not clear. So this point should be very clear, although it is almost trivial.
Jan
2012 年 11 月 18 日
At first you create a temporary vector:
v = abs(t-T(ii));
Then you find its minimum value and the corresponding index:
[val, index] = min(v)
such that v(index) has the value val.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!