Clear Filters
Clear Filters

How to get minimum value among more than two matrix

2 views (last 30 days)
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 Comments
Stephen23
Stephen23 on 20 Jun 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 on 20 Jun 2017
As an aside, there are many 0s in the last row of each of those matrices so these would be the minimum values.

Sign in to comment.

Answers (1)

Jan
Jan on 20 Jun 2017
Edited: Jan on 20 Jun 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.

Categories

Find more on Descriptive Statistics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!