minimum of an array
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Andrei Bobrov
le 13 Déc 2011
r = [1 3 5];
A1 = A;
A1(r,:) = nan;
[c,idx] = min(A1(:));
[i1,j1] = ind2sub(size(A1),idx);
Plus de réponses (3)
Sean de Wolski
le 12 Déc 2011
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 commentaires
Andrei Bobrov
le 13 Déc 2011
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
le 10 Déc 2011
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 commentaires
Mohsen Davarynejad
le 10 Déc 2011
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 commentaires
Walter Roberson
le 12 Déc 2011
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.
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!