Thread Subject: plotting 3D arrays

Subject: plotting 3D arrays

From: juliette Salexa

Date: 28 May, 2009 20:39:01

Message: 1 of 4

I also posted this on Kluid forums.

I have a 2 x 2 x 1000 array called A, and I want to plot A(1,1,:) , A(1,2,:), A(2,1,:), and A(2,2,:) against their third index.

ie, there should be 4 lines on my plot with the x-axis running from 1 to 1000 and the y axis just being the values of A(i,j,:) at each of those 1000 points.

But size(A(1,1,:))=1,1,1000 rather than just 1000 , so I can't plot A(1,1,:) sinse its dimension is larger than 2.

Is there a way around this other than to make new variables to represent A(1,1,:) , etc ... ???

I'd be very shocked if not.

Subject: plotting 3D arrays

From: us

Date: 28 May, 2009 21:04:02

Message: 2 of 4

"juliette Salexa" <n_dattani@hotmail.com> wrote in message <gvmsp5$efu$1@fred.mathworks.com>...
> I also posted this on Kluid forums.
>
> I have a 2 x 2 x 1000 array called A, and I want to plot A(1,1,:) , A(1,2,:), A(2,1,:), and A(2,2,:) against their third index.
>
> ie, there should be 4 lines on my plot with the x-axis running from 1 to 1000 and the y axis just being the values of A(i,j,:) at each of those 1000 points.
>
> But size(A(1,1,:))=1,1,1000 rather than just 1000 , so I can't plot A(1,1,:) sinse its dimension is larger than 2.
>
> Is there a way around this other than to make new variables to represent A(1,1,:) , etc ... ???
>
> I'd be very shocked if not.

one of the solutions

% the data
     m=reshape(1:2*2*10,[2,2,10]);
     x=1:10;
     ix=[
          1 1
          1 2
          2 1
          2 2
     ];
% the engine
for i=1:size(ix,1)
     cm=squeeze(m(ix(i,1),ix(i,2),:));
     line(x,cm,'marker','.');
end

us

Subject: plotting 3D arrays

From: Alan B

Date: 28 May, 2009 21:05:02

Message: 3 of 4

"juliette Salexa" <n_dattani@hotmail.com> wrote in message <gvmsp5$efu$1@fred.mathworks.com>...
> I also posted this on Kluid forums.
>
> I have a 2 x 2 x 1000 array called A, and I want to plot A(1,1,:) , A(1,2,:), A(2,1,:), and A(2,2,:) against their third index.
>
> ie, there should be 4 lines on my plot with the x-axis running from 1 to 1000 and the y axis just being the values of A(i,j,:) at each of those 1000 points.
>
> But size(A(1,1,:))=1,1,1000 rather than just 1000 , so I can't plot A(1,1,:) sinse its dimension is larger than 2.
>
> Is there a way around this other than to make new variables to represent A(1,1,:) , etc ... ???
>
> I'd be very shocked if not.

plot(squeeze(A(1,1,:)))

Subject: plotting 3D arrays

From: Juliette Salexa

Date: 29 May, 2009 16:15:20

Message: 4 of 4

"Alan B" <monguin61@yahoo.com> wrote in message

AMAZING! Squeeze is exactly what I needed!

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
code us 28 May, 2009 17:09:03
reshape us 28 May, 2009 17:09:03
squeeze us 28 May, 2009 17:09:03
line us 28 May, 2009 17:09:03
graphics handle us 28 May, 2009 17:09:03
rssFeed for this Thread

Contact us at files@mathworks.com