Index with min command

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

Matt J
Matt J 2012년 11월 18일
What doesn't make sense about the behavior you're seeing?
SAZZAD HOSSAIN
SAZZAD HOSSAIN 2012년 11월 18일
for each loop there is a min value. but i dont understad how the index assigned to the value is related to "t" or "T".

댓글을 달려면 로그인하십시오.

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 18일
편집: Azzi Abdelmalek 2012년 11월 18일

0 개 추천

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

Jan
Jan 2012년 11월 18일
No, index is not the position of the minimal value of t. This would be [val, index] = min(t).
Azzi Abdelmalek
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
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
Jan 2012년 11월 18일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

태그

질문:

2012년 11월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by