minimum of an array

8 Ansichten (letzte 30 Tage)
Rakshmy  C S
Rakshmy C S am 10 Dez. 2011
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.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 13 Dez. 2011
r = [1 3 5];
A1 = A;
A1(r,:) = nan;
[c,idx] = min(A1(:));
[i1,j1] = ind2sub(size(A1),idx);
  1 Kommentar
Rakshmy  C S
Rakshmy C S am 13 Dez. 2011
thanks a lot.its working.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (3)

Sean de Wolski
Sean de Wolski am 12 Dez. 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 Kommentare
Andrei Bobrov
Andrei Bobrov am 13 Dez. 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)
Rakshmy  C S
Rakshmy C S am 13 Dez. 2011
Thank you. this code is also working

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 10 Dez. 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 Kommentare
Rakshmy  C S
Rakshmy C S am 10 Dez. 2011
i want to find the minimum over the entire array but excluding the content of row2 and 5
Walter Roberson
Walter Roberson am 10 Dez. 2011
min(min(A(setdiff(1:size(A,1), [2 5]),:)))

Melden Sie sich an, um zu kommentieren.


Mohsen  Davarynejad
Mohsen Davarynejad am 10 Dez. 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 Kommentare
Rakshmy  C S
Rakshmy C S am 12 Dez. 2011
Sorry its not working, i am having the values as given below.It is a 10*10 array. I want to find the minimum value of the elements of array excluding [1,3,5].So the value is 1.7321. and the index is 6,7 or 7,6. But after executing the above code i get 6,9 as the index.
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, 5.385, 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
Walter Roberson
Walter Roberson am 12 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by