Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
plotting three dimensional array

Subject: plotting three dimensional array

From: Erik L

Date: 8 Jun, 2010 20:20:21

Message: 1 of 7

Hello,

I have a three dimensional array, tried plot3(matrix) but gives the following error.
?? Error using ==> plot3
Data may not have more than 2 dimensions

Is there a way to plot three dimensional array(matrix).

thanks

Subject: plotting three dimensional array

From: sscnekro

Date: 8 Jun, 2010 20:44:04

Message: 2 of 7

> I have a three dimensional array, tried plot3(matrix) but gives the following error.
> ?? Error using ==> plot3
> Data may not have more than 2 dimensions

Mhmm, I guess it's because you should use 3 input arguments with plot3(). For instance, if your matrix M is N x 3, do:
plot3(M(:,1), M(:,2), M(:,3))

Subject: plotting three dimensional array

From: sscnekro

Date: 8 Jun, 2010 21:05:19

Message: 3 of 7

> Mhmm, I guess it's because you should use 3 input arguments with plot3(). For instance, if your matrix M is N x 3, do:
> plot3(M(:,1), M(:,2), M(:,3))

Sorry, sorry, typos. With either plot3() or mesh() incl. related you need 3 inputs, but: any of those inputs need to be 2D .. whereas you were asking how to plot a 3D M matrix. In that even, I don't know .. maybe you'd see a way to refer to 2D parts of the 3D matrix and plote those.

Subject: plotting three dimensional array

From: Walter Roberson

Date: 8 Jun, 2010 21:04:51

Message: 4 of 7

Erik L wrote:

> I have a three dimensional array, tried plot3(matrix) but gives the
> following error.
> ?? Error using ==> plot3
> Data may not have more than 2 dimensions
>
> Is there a way to plot three dimensional array(matrix).

What do the dimensions _mean_ ?

If it is a 3 dimensional matrix of values, then you are trying to plot 4
dimensions, which is not directly possible. It would be possible to build a
solid 3D grid of values and plot the values as colors (but not simple), but if
  you do that then you would have to use transparency in order to be able to
see part-way inside (and should not expect to be able to see very far inside.)

If you are trying to do voxel imaging, then unfortunately Matlab is not very
suited for that.

Subject: plotting three dimensional array

From: Erik L

Date: 8 Jun, 2010 22:11:04

Message: 5 of 7

dear walter,

Thanks for reply.
I have a matrix A(5,6,9) meaning that it has got separate matrices each having 5 rows and 6 columns for each third dimension [1....to 9].
like A(:,:,1)......A(:,:,9)
I have updated the matrix A according to my algorithm and now want to plot the comparative values column-wise of all matrices for the third dimension[1,,,9].

I should see something like:

on X-axs.....values from 1 to 9( the third dimension)
on y-axs.....the weights of the values inside the matrices
on z-axs.....the values 1 to 6 which are the columns of matrices

thanks

Walter Roberson <roberson@hushmail.com> wrote in message <humbco$c2o$1@canopus.cc.umanitoba.ca>...
> Erik L wrote:
>
> > I have a three dimensional array, tried plot3(matrix) but gives the
> > following error.
> > ?? Error using ==> plot3
> > Data may not have more than 2 dimensions
> >
> > Is there a way to plot three dimensional array(matrix).
>
> What do the dimensions _mean_ ?
>
> If it is a 3 dimensional matrix of values, then you are trying to plot 4
> dimensions, which is not directly possible. It would be possible to build a
> solid 3D grid of values and plot the values as colors (but not simple), but if
> you do that then you would have to use transparency in order to be able to
> see part-way inside (and should not expect to be able to see very far inside.)
>
> If you are trying to do voxel imaging, then unfortunately Matlab is not very
> suited for that.

Subject: plotting three dimensional array

From: Walter Roberson

Date: 8 Jun, 2010 22:25:05

Message: 6 of 7

Erik L wrote:
> I have a matrix A(5,6,9) meaning that it has got separate matrices each
> having 5 rows and 6 columns for each third dimension [1....to 9].
> like A(:,:,1)......A(:,:,9)
> I have updated the matrix A according to my algorithm and now want to
> plot the comparative values column-wise of all matrices for the third
> dimension[1,,,9].
>
> I should see something like:
>
> on X-axs.....values from 1 to 9( the third dimension)
> on y-axs.....the weights of the values inside the matrices
> on z-axs.....the values 1 to 6 which are the columns of matrices

I'm not sure what you mean by "the weights of the values inside the matrices".

Anyhow, on some axes, you need to display the actual _value_ A(J,K,L). You are
already using x, y, and z, so the value of the cells would need to be plotted
in t (time), or in color. Earlier I described some of the difficulties of
using color in 3D, and you haven't mentioned color at all, but you also
haven't mentioned any kind of animation. What were you envisioning?


Instead of plotting as you have described, would it be acceptable to plot 9
different 3D plots, P=1:9, A(:,:,P) ? If so then see subplot()

Subject: plotting three dimensional array

From: sscnekro

Date: 8 Jun, 2010 23:20:20

Message: 7 of 7

I have nothing to add (and do not aim so) to the advise above, it's just that I hit on the error message " ??? Error using ==> plot3 Data may not have more than 2 dimensions" by typing

plot3(A(1,1,:),A(2,2,:),A(1,2,:)); % A .. < 2 x 2 x 3 double>

Maybe this is what confused you. I myself personally wrongly assumed that A(1,1,:) 'd be 2D. You may extract your data (the 3rd dimension) by

B = permute(A, [3 2 1]).

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us