Using Figure

147 次查看(过去 30 天)
Villanova
Villanova 2011-12-11
I remember there was a command to plot multiple graphs on seperate plots. Does anyone know how you do that:
figure(1)
plot(t,x(:,1),'red','linewidth',2 )
xlabel('Time (s)');
ylabel('X_1');
figure (2)
plot(t,x(:,2),'blue','linewidth',2 )
xlabel('Time (s)');
ylabel('X_2');
I know it has to do with 'Figure' command on the fist line. Thanks

采纳的回答

Walter Roberson
Walter Roberson 2011-12-11
h1 = figure(1);
ax1 = axes('Parent', h1);
plot(ax1, t,x(:,1),'red','linewidth',2 )
xlabel(ax1, 'Time (s)');
ylabel(ax1, 'X_1');
h2 = figure(2);
ax2 = axes('Parent', h2);
plot(ax2, t,x(:,2),'blue','linewidth',2 )
xlabel(ax2, 'Time (s)');
ylabel(ax2, 'X_2');
I explain why to explicitly parent graphics in my comment in http://www.mathworks.com/matlabcentral/answers/22208-show-figure

更多回答(1 个)

Paulo Silva
Paulo Silva 2011-12-11
doc subplot
example
t=0.01:0.01:1;
x=rand(100,2);
subplot(211)
plot(t,x(:,1),'red','linewidth',2 )
xlabel('Time (s)');
ylabel('X_1');
subplot(212)
plot(t,x(:,2),'blue','linewidth',2 )
xlabel('Time (s)');
ylabel('X_2');
another way
t=0.01:0.01:1;
x=rand(100,2);
clf
hold on
plot(t,x(:,1),'red','linewidth',2 )
xlabel('Time (s)');
ylabel('X');
plot(t,x(:,2),'blue','linewidth',2 )
xlabel('Time (s)');
ylabel('X');
legend('X_1','X_2')

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by