How to get minimum value among more than two matrix

조회 수: 4 (최근 30일)
Vishal Sharma
Vishal Sharma 2017년 6월 20일
편집: Jan 2017년 6월 20일
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