Finding the Maximum of 6 matrices
1 次查看(过去 30 天)
显示 更早的评论
I have 6 41*41 matrices. They contain peak displacement data for a combination of variables which I have changed
I.e. I would have a matrix which would look like this for example: where the kiso values are going down and the ciso vaules are going across and the values are the correspsonding data for each combination.
M1=
ciso
kiso 1 2 3
1 3.4 3 0.5
2 8 5.6 0.23
3 2 4.3 0.56
M2=
ciso
kiso 1 2 3
1 4 5 6
2 0.1 5.2 0.2
3 9 4 0.5
Max=
ciso
kiso 1 2 3
1 4 5 6
2 8 5.6 0.23
3 9 4.3 0.56
How do I compare each matrix and build a separate matrix which has the maximum value for each kiso and ciso combination as I have done in the example?
I have tried the matrix max comparison max(A,B) etc but I get an error saying there are too many input arguments as I am comparing 6 matrices not 2. max_building=max(Peak_mat1,Peak_mat2,Peak_mat3,Peak_mat4,Peak_mat5,Peak_mat6);
Thanks in advance
0 个评论
回答(3 个)
njj1
2018-4-24
You can use max(X,[],dim) to specify the dimension from which to compute the maximum value. For example, if you let dim=2, then this computes the maximum value across each row of your matrix, resulting in a column vector; while dim=1 takes the maximum over each column of your matrix, resulting in a row vector. You could also try to re-arrange your data into a 41x41x6 array, where each "slice" in this 3-D cube is one of your original matrices. If you then entered max(X,[],3), you would get a 41x41 matrix where each entry is the maximum value of that particular (i,j) location for each of the 6 41x41 matrices. You could then pare this down into a maximum value for all columns and all rows over all the 6 matrices. One way to do this is: max(max(X,[],3),[],2) to get the max across each row for all 6 arrays. To do this same thing for columns: max(max(X,[],3),[],1). Hope this helps!
dpb
2018-4-24
The problem is the creation of sequentially named variables instead of using a form of data storage that makes addressing the data easy programmatically.
The simplest conceptually for the 2D arrays would be to create a 3D array where each of the six is a plane (3rd dimension); then you can simply address each by the desired index 1 thru 6.
If you create the M array in that fashion for the above case you'd have
M(:,:,1) =
3.4000 3.0000 0.5000
8.0000 5.6000 0.2300
2.0000 4.3000 0.5600
M(:,:,2) =
4.0000 5.0000 6.0000
0.1000 5.2000 0.2000
9.0000 4.0000 0.5000
>>
and the desired max are simply
>> max(M,[],3)
ans =
4.0000 5.0000 6.0000
8.0000 5.6000 0.2300
9.0000 4.3000 0.5600
>>
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!