plotting 3-D data in 2-D

Hi again,
I have a 3D matrix (test=rand(3,3,4)) and I'm trying to plot each 2D entry through the third dimension [i.e. plot nine lines: (1,1,:),(1,2,:) and so on]. I'm not exactly sure how to do this, and can't get it to work with plot or plot3.
Any ideas?
Thanks,
Don

 採用された回答

Sean de Wolski
Sean de Wolski 2011 年 6 月 15 日

1 投票

test = repmat(magic(3),[1 1 4]); %each vector into the third dimension will be the same (so we can verify accuracy)
test2 = reshape(permute(test,[3 2 1]),size(test,3),[]); %permute it and reshape it so that each column represents one vector into the third dimension
plot(test2) %plot it

5 件のコメント

Donald
Donald 2011 年 6 月 15 日
Thank you for your help! As you probably have figured, I'm just starting out with Matlab.
Donald
Donald 2011 年 6 月 15 日
Just a quick question:
Why is the [] necessary in the reshape command? What exactly is it doing?
Sean de Wolski
Sean de Wolski 2011 年 6 月 15 日
The [] indicates that we don't know how many entries are going to be in that dimension. So reshaping a 4x4 matrix into and 8x2 could be done with either
reshape(A,8,2) or reshape(A,[],2) or reshape(A,8,[]). In the above case there will be 9 columns (3x3) but I assume your test example is probably not the real size of your data so I generalized. It'll work with any sized matrix.
Donald
Donald 2011 年 6 月 21 日
I've been fiddling around with this code and was wondering, is there a way to print the data from each row on a separate graphs? So for this 3x3 matrix have the output 3 charts with three lines each.
Sean de Wolski
Sean de Wolski 2011 年 6 月 21 日
doc subplot
and then a for loop to do the work.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by