필터 지우기
필터 지우기

How to plot a 3 dimensional matrix against its last independent variables?

조회 수: 2 (최근 30일)
suppose that I have a variable 'u' which depends on 3 independent variables 'x', 'y' and 'z'.
If i,j,k indicate x,y,z steps respectively, like suppose that
n=10;
x=linspace(0,1,n);y=linspace(0,1,n);z=linspace(0,1,n);
for i=1:n
for j=1:n
for k=1:n
u(i,j,k)=x(i)+y(j)+z(k);
end
end
end
I want to see the variation of 'u' with 'z'. How can I do that?
I know it will be a straight line in this case but how to plot the graph as plot command plots graphs by considering only first 2 independent variables.
  댓글 수: 5
John BG
John BG 2017년 1월 13일
Udit
wouldn't it be easier to start with a concise definition of u=f(x,y,z)?
is it possible for you to code, if only approximately, the function you write about?
Udit Srivastava
Udit Srivastava 2017년 1월 13일
for a fixed value of x and y, using plot(z,u(3,5,:)) gives the following error.
Error using plot Data cannot have more than 2 dimensions.

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

채택된 답변

John Chilleri
John Chilleri 2017년 1월 13일
편집: John Chilleri 2017년 1월 13일
Hello,
A simple solution to get around your problem is:
for i = 1:size(u,3)
uplot(i) = u(3,5,i);
end
plot(z,uplot)
I believe that the reason it is encountering trouble is because you can think of a 3d array as sheets of 2d arrays, and although it can call x and y across a sheet, it would need to call one z value from each sheet ("2 dimensions") which it can't do, I would take this explanation with a grain of salt.
Hope this helps!
  댓글 수: 1
Udit Srivastava
Udit Srivastava 2017년 1월 15일
Works great. Thanks!
One thing I would like to know how size(u,3) is helping. I mean size(u,3) should give 10 X 10 but it gives 10. Why so?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by