2 views (last 30 days)

Show older comments

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

njj1
on 24 Apr 2018

dpb
on 24 Apr 2018

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

>>

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

Start Hunting!