Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
654 views
in Technique[技术] by (71.8m points)

matlab - Show two different plots in one plot

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Learning Subplots

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

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);

Learning to Hold On

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

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...