MATLAB Answers

M.A.

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

  0 Comments

1 Answer

Answer by Star Strider
on 7 Jun 2014
 Accepted answer

Use the subplot function.

Your loop becomes:

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

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

  6 Comments

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

M.A.
on 7 Jun 2014

thank you so much

Star Strider
on 7 Jun 2014

My pleasure!


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today