Using Figure

324 views (last 30 days)
Villanova
Villanova on 11 Dec 2011
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

Accepted Answer

Walter Roberson
Walter Roberson on 11 Dec 2011
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

More Answers (1)

Paulo Silva
Paulo Silva on 11 Dec 2011
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')

Tags

Community Treasure Hunt

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

Start Hunting!