MATLAB Answers


How can i plot f(i),g(i),h(i) in one figure(i)?

Asked by M.A.
on 7 Jun 2014
Latest activity Commented on by Star Strider
on 7 Jun 2014

I want to plot each three diagrams in one figure


1 Answer

Answer by Star Strider
on 7 Jun 2014
 Accepted answer

Use the subplot function.

Your loop becomes:

for i = 1:3
       . . .
    plot(x,f(i),'-b', ... )
       . . .

to get 3 stacked plots in one figure. Other configurations are possible. See the documentation on subplot for details.


Star Strider
on 7 Jun 2014

I edited the code in my previous comment rather than re-post different code here. It should now do what you want.

The plots look strange because you have ‘axis equal’ in your plot statements. I left that in because it was in your original code. (I took it out when I ran it to be sure everything was plotting correctly.)

on 7 Jun 2014

thank you so much

Star Strider
on 7 Jun 2014

My pleasure!

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!