How to get minimum value among more than two matrix

4 visualizzazioni (ultimi 30 giorni)
Vishal Sharma
Vishal Sharma il 20 Giu 2017
Modificato: Jan il 20 Giu 2017
I have 5 matrix of following values as per below:--
A = [1 2 3;0 0 5]
B = [3 2 3;0 0 3]
C = [1 5 3;0 0 2]
D = [7 2 3;0 0 1]
E = [4 2 3;0 0 7]
I want to find minimum value in the last row (i.e. second row) and its index also, so that the final result should be as follows:--
Minimum value = 1
Index = D(2,3)
Also, please tell how to find matrix having closest to particular value, say 3 in second row among A, B, C, D, E matrix's... So, as to get the result as per below:--
Value = 3
Matrix = B(2,3)
  3 Commenti
Stephen23
Stephen23 il 20 Giu 2017
"I have 5 matrix ..."
Well, that is the problem right there. If you simply put all of your data into one array then this task would be trivially simple. Put all of your data into lots of separate arrays and you waste your life trying to figure out solutions to problems instead.
Solution: concatenate your data into one array. Then use min.
Adam
Adam il 20 Giu 2017
As an aside, there are many 0s in the last row of each of those matrices so these would be the minimum values.

Accedi per commentare.

Risposte (1)

Jan
Jan il 20 Giu 2017
Modificato: Jan il 20 Giu 2017
Do not store the arrays in different variables, but as an array:
A = [1 2 3;0 0 5]
B = [3 2 3;0 0 3]
C = [1 5 3;0 0 2]
D = [7 2 3;0 0 1]
E = [4 2 3;0 0 7]
Data = {A,B,C,D,E};
Now run a loop:
minValue = Inf;
minIndex = 0;
minArg = 0;
for k = 1:numel(Data)
[aMin, aIndex] = min(Data{k}(2, :));
if aMin < minValue
minValue = aMin;
minIndex = aIndex;
minArg = k;
end
end
Well, a numerical array would be much easier.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by