Plotting outputs from a function on one figure using for loop

조회 수: 1 (최근 30일)
william Smith
william Smith 2019년 3월 8일
댓글: KSSV 2019년 3월 8일
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!!

답변 (1개)

KSSV
KSSV 2019년 3월 8일
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
william Smith
william Smith 2019년 3월 8일
could you please edit my code cannot visualize how to set it up in the for loop
Thanks
KSSV
KSSV 2019년 3월 8일
YOu have entire data as matrrix outside....you can plot it outside. Read about plot

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by