How to use loops for specific numbers

조회 수: 6 (최근 30일)
Jose De La Pena
Jose De La Pena 2019년 12월 3일
편집: Jose De La Pena 2019년 12월 6일
So, I have a projectile for which I have created a User-Defined function for, however, the question asks to use the user defined functions for a set number of velocities and angles. The user defined function accepts two inputs (velocity,angle). The question asks to use these following velocities and angles:
velocity= [30,40,47.16];
angle=[5,7.5,10,30,45,60];
So, the question asks to create a loop to create a graph. I'm having trouble creating the actual loop, here is what I have thus far,
%Ball Trajectory Graph
%Define the for loop first
velocity= [30,40,47.16];
angle=[5,7.5,10,30,45,60];
for ii=1:length(velocity)
velocity=velocity(ii);
for iii=1:length(angle)
angle=angle(iii);
DeLaPena_Trajectory(velocity,angle)
end
end
Here's what I know: The total amount of loops to be completed is 3, in which it calculates for each velocity the angles specified once. The main problem I am having is actually getting the loop to insert said velocites and angles. Any hints would greatly be appreciated.

채택된 답변

Walter Roberson
Walter Roberson 2019년 12월 3일
%Ball Trajectory Graph
%Define the for loop first
velocity= [30,40,47.16];
angle=[5,7.5,10,30,45,60];
for ii=1:length(velocity)
this_velocity=velocity(ii);
for iii=1:length(angle)
this_angle=angle(iii);
output(ii,iii) = DeLaPena_Trajectory(this_velocity,this_angle);
end
end
  댓글 수: 1
Jose De La Pena
Jose De La Pena 2019년 12월 6일
편집: Jose De La Pena 2019년 12월 6일
The code runs, but it only stores the x value not the y value of the anonymous function. I have no clue as to where the y-value goes. Also, how does MatLab know to default to only the x-value and not the y-value? Since the output(ii,iii) is assigning it to one specific index, it can only store one value.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by