Reputation: 13
I am working with Matcont in Matlab and I have a problem with plotting. I am using a special built-in function of Matcont to plot and I would like to display two separate plots in one.
In mathematica I would use the show function.
a=cpl(x,v,s,[4 1])
b=cpl(x1,v1,s1,[4 1])
Show[{a, b}]
I am looking for the same Show function in matlab.
Upvotes: 1
Views: 305
Reputation: 2488
In matlab this is done using the subplot
function.
Here is the reference.
Basically you first create a figure, then divide it into a 2-D grid using the first two arguments to subplot:
subplot(2, 2, 1);
for example would create a 2-by-2 grid -- thus creating space for 4 plots. The last index 1
selects the first plot of the grid, i.e. the plot in position (0, 0) starting from the top left corner of the figure area.
subplot(2, 2, 3);
Would instead select the third plot, i.e. the plot in position (1, 0) starting from the top left corner of the figure area.
A working example in your case would be
figure(1); % Create new figure #1
clf; % Clear the figure
% Compute the data
a=cpl(x,v,s,[4 1])
b=cpl(x1,v1,s1,[4 1])
% Plot it
subplot(2, 1, 1);
plot(a);
subplot(2, 1, 2);
plot(b);
If, as others mentioned, you are instead trying to plot two curves on the same pair of axes, the hold function is what you need. Without the hold your second plot command would in fact overwrite the first plot.
A working example in your case would be
figure(1); % Create new figure #1
clf; % Clear the figure
% Compute the data
a=cpl(x,v,s,[4 1])
b=cpl(x1,v1,s1,[4 1])
% Plot it
plot(a);
hold on;
plot(b);
Upvotes: 2
Reputation: 21561
As @Dan already mentioned in the comments, it seems like you try to do something like this:
a=1:10
b=a.^2
plot(a)
hold on
plot(b)
Upvotes: 1