필터 지우기
필터 지우기

Find Min/Max Value of a Column in a Matrix

조회 수: 6 (최근 30일)
Trier87
Trier87 2012년 12월 25일
Hello and Happy Christmas. i have a Variable Buff that is a 231x3 Matrix. My Code looks like this:
Buff = zeros(numel(1286:10:1486)*numel(873:10:973),3);
Ctr = 1;
for step1 = 1286:10:1486
for step2=873:10:973
Main
Buff(Ctr, 1) = step2;
Buff(Ctr, 2) = step1;
Buff(Ctr, 3) = J_Bolzen;
Ctr = Ctr+1;
end
end
save test.dat Buff;
So i have 3 Columns, Column1=step2, Column2=step1 and Column3=J_Bolzen. Now i want find the min Value of the Column3 and the associated Position in the Matrix ( Row and Column ). My first attempt was:
[r c] =find(Buff==min(Buff(:)))
but it looks for the min value of the whole Matrix. It should looks for the min value of Column3 of the Matrix Buff and give the output for that min value and their position in the Matrix
Thanks Guys :-D

채택된 답변

vipul utsav
vipul utsav 2012년 12월 25일
[r c] =find(Buff==min(Buff(:,3)))
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 12월 25일
This will return 1 as the column instead of the 3 reflecting the origin in column 3.

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2012년 12월 25일
[minval, minidx] = min(Buff(:,3));
The minimum value would be minval, and the position would be (minidx, 3)

Trier87
Trier87 2012년 12월 25일
Thanks it works fine. Is it now possible to give the outpout for the other two colummns too. So i had the min value of column3 and the position ( which row ) and the the two other values of column1 and column2 for the min value of column3
Big Thanks

카테고리

Help CenterFile Exchange에서 Christmas / Winter에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by