minimum of an array
2 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have a 10*10 array.I need to find the minium of all the rows of the array except selected ones.For eg. to find the minimum of the array except 2nd and fifthrow.
0 件のコメント
採用された回答
Andrei Bobrov
2011 年 12 月 13 日
r = [1 3 5];
A1 = A;
A1(r,:) = nan;
[c,idx] = min(A1(:));
[i1,j1] = ind2sub(size(A1),idx);
その他の回答 (3 件)
Sean de Wolski
2011 年 12 月 12 日
A = [999, 25.019, 1.414, 25.806, 1.414, 3.316, 4.472, 29.782, 26.248, 28.248
25.019, 999, 25.059, 5.291, 25.495, 25.278, 25.573, 8.774, 3.316, 7.348
1.414, 25.059, 999, 25.612, 2.449, 4.358, 5.477, 29.546, 26.134, 28.035
25.806, 5.291, 25.612, 999, 26.495, 26.514, 27.092, 5.385, 4.795, 8.124
1.414, 25.495, 2.449, 26.495, 999, 2.236, 3.162, 30.577, 26.739, 28.635
3.316, 25.278, 4.358, 26.514, 2.236, 999, 1.732, 30.822, 26.645, 28.513
4.472, 25.573, 5.477, 27.092, 3.162, 1.732, 999, 31.416, 26.925, 28.670
29.782, 8.774, 29.546, 0, 30.577, 30.822, 31.416, 999, 7.874, 10.535
26.248, 3.316, 26.134, 4.795, 26.739, 26.645, 26.925, 7.874, 999, 4.358
28.248, 7.348, 28.035, 8.124, 28.635, 28.513, 28.670, 10.535, 4.358, 999];
exc = [1 3 5];
[Amin idc] = min(A(setdiff(1:size(A,1), exc),:),[],2);
[Amin idr] = min(Amin);
idc = idc(idr);
idr = idr+sum(exc<=idr);
fprintf('Minimum %f at row %i col %i\n',Amin,idr,idc);
Minimum 0.000000 at row 8 col 4
I added a zero to test it.
5 件のコメント
Andrei Bobrov
2011 年 12 月 13 日
small corrected
r1 = setdiff(1:size(A,1),exc)
[Amin,idr] = min(A(r1,:))
[Amin,idc] = min(Amin)
idr = r1(idr(idc))
or
r1 = setdiff(1:size(A,1),exc)
[Amin,c1] = min(A(r1,:),[],2)
[Amin,r2] = min(Amin)
idc = c1(r2)
idr = r1(r2)
Walter Roberson
2011 年 12 月 10 日
Create a new matrix that includes only the desired information, and apply the minimum to that.
This can possibly be done without any assignment to variables, by using indexing, but whether you will be able to handle things that way depends on your intention.
B = A; %work on a copy, not the original
B([2 5],:) = []; %remove the 2nd and 5th rows
%now apply the appropriate min() function to B.
or
apply min() to A(setdiff(1:size(A,1), [2 5]),:)
I am being vague about the min because I cannot tell whether you mean minimum across each row with rows 2 and 5 happening not to be wanted; or if you minimum down each column after row 2 and 5 have been ignored; or if you want the minimum over the entire array but excluding the content of rows 2 and 5.
2 件のコメント
Mohsen Davarynejad
2011 年 12 月 10 日
My guess is the the following scales better:
B = A; %work on a copy, not the original
B([2 5],:) = []; %remove the 2nd and 5th rows
[Min, MinIndex] = min(B(:));
9 件のコメント
Walter Roberson
2011 年 12 月 12 日
I see what you mean, and I have an idea of how to correct for it, but I need to work on other things now.
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!