How to get minimum value among more than two matrix

4 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2017-6-20
"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 2017-6-20
As an aside, there are many 0s in the last row of each of those matrices so these would be the minimum values.

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2017-6-20
编辑:Jan 2017-6-20
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.

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by