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
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
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
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!