## Plotting multiple matrices in the same plot, so i can seee how the matrices develop trough time?

Asked by Walter Manns

### Walter Manns (view profile)

on 7 Oct 2011
Accepted Answer by Grzegorz Knor

### Grzegorz Knor (view profile)

Sorry for the horrible english, but i don't know how to explain it otherwise.

I want to plot these matrices:

val(:,:,1) =

```    18    18    18    18    18
18    18    18    18    18
18    18    18    18    18
18    18    18    18    18
18    18    18    18    18```

val(:,:,2) =

```    18    18    18    18   120
18    18    18    18   120
18    18    18    18   120
18    18    18    18   120
120   120   120   120   120```

val(:,:,3) =

```   18.0000   18.0000   18.0000   18.9139  120.0000
18.0000   18.0000   18.0000   18.9139  120.0000
18.0000   18.0000   18.0000   18.9139  120.0000
19.0662   19.0662   19.0662   19.9802  120.0000
120.0000  120.0000  120.0000  120.0000  120.0000```

val(:,:,4) =

```   18.0000   18.0000   18.0082   19.8115  120.0000
18.0000   18.0000   18.0082   19.8115  120.0000
18.0119   18.0119   18.0201   19.8234  120.0000
20.1118   20.1118   20.1200   21.9041  120.0000
120.0000  120.0000  120.0000  120.0000  120.0000```

On the same graph, so i can see (with colors) how the matrices develop trough time. The matrix itself shows me the spacial location. The numbers on the matrix shows the temperature, and the first matrix is time = 1, the next time = 2, then time = 3 and last time=4.

Thanks.. :D

Walter Manns

### Walter Manns (view profile)

on 7 Oct 2011

The colors should indicate the temperature (120°C should be red, to indicate heat and 18°C blue).

## Products

No products are associated with this question.

### Grzegorz Knor (view profile)

Answer by Grzegorz Knor

### Grzegorz Knor (view profile)

on 7 Oct 2011

My suggestion:

```for k=1:size(val,3)
imagesc(val(:,:,k))
colorbar
caxis([18 120])
drawnow
pause(1)
end
```

Grzegorz Knor

on 7 Oct 2011

doc slice

Walter Manns

### Walter Manns (view profile)

on 7 Oct 2011

It works. But, do you know can i make the plot smoother?

### Elige Grant (view profile)

Answer by Elige Grant

### Elige Grant (view profile)

on 7 Oct 2011

If you want to make a movie to use outside of Matlab, then look up "getframe" and something like "movie2avi" in the Navigation Help. For example:

```for k=1:size(val,3)
handle = imagesc(val(:,:,k))
colorbar
caxis([18 120])
save_frame(k) = getframe(handle);
end
```
```movie2avi(save_frame,'MyMovie.avi')
```

You can adjust the rate that frames are displayed per second (see Help for more info).

Walter Manns

### Walter Manns (view profile)

on 7 Oct 2011

Thanks Grant, very helpfull. The problem is that i see squares changing color, and i can't fin out how to make it smoother. One solution is changing the programming for getting those matrices from 5x5 to 10x10, but i get so much data if i do this i cannot see the results (matlab doesn't let me because they are more than 540,000 data values or something like that). Can i use another plotting form, instead of imagesc, to make a smoother image?

Thanks for the help!

Elige Grant

### Elige Grant (view profile)

on 7 Oct 2011

Check out "interp2" in the Navigation Help. Instead of calculating and storing a bigger NxN matrix for each time stamp, you might be able to interpolate between the calculated points and use this more dense version for display purposes only.

For N = 5:

[X,Y] = meshgrid(1:5);
[X1,Y1]=meshgrid(1:0.1:5);
handle = imagesc(interp2(X,Y,val(:,:,k),X1,Y1));

Put the definition of X,Y,X1, and Y1 before the for loop... since these do not need to be redefined after each loop iteration.

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi