Two Plotting results one at a time like simulation

조회 수: 1 (최근 30일)
onur karakurt
onur karakurt 2024년 7월 22일
댓글: Voss 2024년 7월 22일
x=linspace(0,-1.2903,100);
u=deg2rad(7)
rho1 = 1.3;
ha = 2;
for i=1:length(x)
eqn1 = @(rho1, u, x) -rho1*cos(u)-x;
U(i) = fminsearch(@(u)norm(eqn1(rho1,u,x(i))),u);
y(i) = +ha-rho1+rho1*sin(U(i));
Slope(i) =atand(cot(U(i)));
end
% create the figure and an empty plot graphics handles
figure;
hPlot = plot(NaN,NaN);
% set the limits
xlim([min(x) max(x)]);
ylim([min(y) max(y)]);
Ulim([min(U) max(U)]);
% draw the curve
for k=1:length(x)
% update the data
set(hPlot,'XData',x(1:k),'YData',y(1:k),hPlot,'XData',x(1:k),'UData',U(1:k));
% pause for 0.1 seconds
pause(0.1);
end
Hey guys,can someone help me with this? Its not working with 3 variables I want to see x and y plot at a time, at the same time I want to see x and U variable in plot at a time,something like a simulation... Appreciate the help!!!

채택된 답변

Voss
Voss 2024년 7월 22일
Let's say you have these x, y, and Slope variables:
x = linspace(0,1,100);
y = exp(x/2);
Slope = 0.5*y;
Then to plot y and Slope vs x, adding one point at a time, you can do this:
% create the figure and an empty plot graphics handles
figure;
hold on
h_y = plot(NaN,NaN);
h_slope = plot(NaN,NaN);
% set the limits
xlim([min(x) max(x)]);
ylim([min([y Slope]) max([y Slope])]);
% draw the curves
for k=1:length(x)
% update the data
set(h_y,'XData',x(1:k),'YData',y(1:k));
set(h_slope,'XData',x(1:k),'YData',Slope(1:k));
% pause for 0.1 seconds
pause(0.1);
end
  댓글 수: 4
onur karakurt
onur karakurt 2024년 7월 22일
thanks a lot
Voss
Voss 2024년 7월 22일
You're welcome!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by