Plotting outputs from a function on one figure using for loop

Hello,
I need help with the following question please, I am calculating the outputs for this function at different friction and initial elevation values, and I would like to plot all of them on one graph, sor for instance I need to plot x_direction vs y_direction for every friction value
function[v_a, x_direction, y_direction, v_b, t_flight]=func(friction, initialelevation)
friction= 0.1 : 0.05 : 0.65
initialelevation= 100 : 15 : 200
% this is what i am using so far but not sure how to put the plotting in there
for j = 1:friction
for n = 1:initialelevation
[v_a(j,n), x_direction(j,n), y_direction(j,n), v_b(j,n), t_flight(j,n)] = func(friction(j), initialelevation(n));
end
end
Please help!!

Answers (1)

YOu should follow some thing like shown below:
friction= 0.1 : 0.05 : 0.65 ;
initialelevation= 100 : 15 : 200 ;
function[v_a, x_direction, y_direction, v_b, t_flight]=func(friction, initialelevation)
m = length(friction) ;
n = length(initialelevation) ;
v_a = zeros(m,n) ;
x_direction = zeros(m,n) ;
y_direction = zeros(m,n) ;
v_b = zeros(m,n) ;
t_flight = zeros(m,n) ;
% this is what i am using so far but not sure how to put the plotting in there
for i = 1:friction
for j = 1:initialelevation
[va, xdirection, ydirection, vb, tflight] = func(friction(i), initialelevation(j));
v_a(i,j) = va ;
x_direction(i,j) = xdirection ;
y_direction(i,j) = ydirection ;
v_b(i,j) = vb ;
t_flight(i,j) = tflight ;
end
end

4 Comments

thank you,
in this case i got different values for xdirection and ydirection. how do i setup the plotting of all of them in one graph?
for instance i have values now at 0.1 and 0.15.... till 0.65 how do i plot every individual data set on the same graph
thanks again!
could you please edit my code cannot visualize how to set it up in the for loop
Thanks
YOu have entire data as matrrix outside....you can plot it outside. Read about plot

Sign in to comment.

Products

Release

R2018b

Asked:

on 8 Mar 2019

Commented:

on 8 Mar 2019

Community Treasure Hunt

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

Start Hunting!