I would like your help. I am newbie in MATLAB. In my program I calculate 2D plot profiles as the attached pic.
on this Y-X 2D plot, the Y array being calculated for 10 time steps. I would like to make a surface evolution of all this plots around x=0; at least for the last one. Eventually to create a surface 3Dplot, like a half sphere. The Z axis could be the same as X axis; so the radius to be from 0 to 1 according the attached pic. Please, can someone help me on this? Any idea is more than welcome. thank you.

 채택된 답변

Mischa Kim
Mischa Kim 2014년 2월 26일

0 개 추천

Konstantinos, try this one:
R = 0:0.1:1;
z = cos(-R); % that'd be your current y-function
th = 0:pi/20:2*pi;
X = bsxfun(@times,R',cos(th));
Y = bsxfun(@times,R',sin(th));
Z = repmat(z',1,length(th));
surf(X,Y,Z)
box

댓글 수: 6

K.
K. 2014년 2월 26일
Hej Mischa, thank you so much for your reply. It is amazing working! :) I have tried something similar but without success. The only change I done is the R input which is from -1 to +1 in my case, cause my z has values on the above spectrum. In my script I get a lot of these lines, cause I use time loop and the z depend by the time. Eventually I have a matrix z, in which every column has the values from the corresponded time. I have done a 2D plotting of all these graphs. Could be possible to use your answer, but having z matrix? if not I will use it individual for every column of the matrix, right? Thank you!
K.
K. 2014년 2월 26일
Eventually I would like to use all these 3D plots to make an animation, as I have an expansion of the initial form.
Mischa Kim
Mischa Kim 2014년 2월 26일
편집: Mischa Kim 2014년 2월 26일
Sure you can. Try
R = 0:0.1:1;
z = cos(-R); % that'd be your current y-function
th = 0:pi/20:2*pi;
X = bsxfun(@times,R',cos(th));
Y = bsxfun(@times,R',sin(th));
Z = repmat(z',1,length(th));
sh = surf(X,Y,Z);
box
tspan = 0:0.2:2*pi;
set(gca,'zlim',[0 1],'ylim',[-5 5]) % keep limits on z and y axis
for ii = 1:length(tspan)
z = cos(-R)*(1+0.1*sin(tspan(ii)));
Z = repmat(z',1,length(th));
Y = Y*(1+0.1*sin(tspan(ii)));
set(sh,'zdata',Z,'ydata',Y) % refresh Z, Y matrix
pause(0.05)
end
K.
K. 2014년 2월 26일
You are amazing! thank you! just to ask something. Is it possible to have "steady" Y axis without changing according the maximum value of the Y function? So eventually I can view the animation like a really one. In my case the T function increasing at x axis and y axis also.
Yep, see updated code above.
set(gca,'zlim',[0 1],'ylim',[-5 5]) % keep limits on z and y axis
Does this answer your questions?
K.
K. 2014년 2월 26일
Yes! I did not try the above answer yet, cause I have two parts on my code. Thank you!!!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

제품

질문:

K.
2014년 2월 26일

댓글:

K.
2014년 2월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by