필터 지우기
필터 지우기

Plotting a 2D matrix

조회 수: 344 (최근 30일)
Alok Pathak
Alok Pathak 2014년 6월 27일
댓글: Gnaneswar Nadh satapathi 2014년 6월 27일
I need to plot a matrix M which is 300*42 in size. On the X axis I need to plot 1:42. On the Y Axis I need to plot the value corresponding to the 42 values. On the Z axis I need to plot the 1:300 value.
I tried using the plot3 function in a loop like this and I wouldnt get it right :
for i = 1:300
plot( 1:42, M(i, 1:42), 1:i);
hold on;
drawnow ;
end
I get the error Vectors are not of similar lengths. Please Help. Many thanks
Regards
  댓글 수: 3
Alok Pathak
Alok Pathak 2014년 6월 27일
The Idea is this. I have recorded a vector of length 42. I have done this process for 300 times. I want to show how the vector changes while i record the vector 300 times. I wanted to show a 3d plot that carries this information.
The vectors are of similar lengths. 1: 42 and M(i,1:42) are both 1*42 double.
Regards
Gnaneswar Nadh satapathi
Gnaneswar Nadh satapathi 2014년 6월 27일
plot it as
surf(M)

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 6월 27일
편집: Andrei Bobrov 2014년 6월 27일
s = size(M);
[z,x] = ndgrid(1:s(1),1:s(2));
data = permute(num2cell(cat(3,x,M,z), 2),[3,2,1]);
plot3(data{:});
or
s = size(M);
[x,z] = ndgrid(1:s(2),1:s(1));
plot3(x,M.',z);

추가 답변 (1개)

David Sanchez
David Sanchez 2014년 6월 27일
Maybe you are thinking no something like this:
M=rand(300,42); % your data here
[xx, yy] = meshgrid(1:42,1:300);
plot3(xx,yy,M,'*')

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by