Multiple plots in a single X and y axis

Hello, I want to write a program that can plot all variables in one graph sheet. A single input variable y-axis and at least 10 input variables on the z-axis.

 Accepted Answer

Use the hold function.
Example —
x = linspace(1, 2, 250);
y1 = sin(2*pi*x*5);
y2 = cos(2*pi*x*7);
figure
plot(x, y1)
hold on
plot(x, y2)
hold off
grid
legend('y2','y2')
.

4 Comments

Thank you. What if it is not sin and cos function, say the various inputs on the x-axis are ...g=[1 3000], q=[150 350], d=[20 55],u=[2500 6000] etc and should be plotted against say... t=[1 15] on the y-axis.
My pleasure!
Try this:
g=[1 3000];
q=[150 350];
d=[20 55];
u=[2500 6000];
gqdu = [g; q; d; u]; % Concatenate Vectors (Must Have Equal Sizes)
t=[1 15];
figure
hold on
for k =1:size(gqdu,1)
plot(t,gqdu(k,:))
end
grid
legend('g','q','d','u', 'Location','NW')
set(gca, 'YScale','log') % Optional
.
Thank you very much. It worked as wanted, but please I want to include value from say...h=[0.2 0.8]. But when I ran it the plots fell exactly on the y-axis. How can I add a second x-axis to accommodate this variables and it will show on the graph.
My pleasure!
I do not understand wanting to add a second x-axis when they are all plotted as functions of ‘t’. You can easily concatenate ‘h’ with the rest, and it will plot correctly, just as with the others. Adding it to the legend call is trivial. Scaling the y-axis to log makes them all easily visible.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!