Store m iterations of a variable in for loop

1 view (last 30 days)
clear all; clc; close all;
%generate random values for VN, VE, VD in vector form
VN_random = randi(100,10,1);%(feet/second)north velocity (column vector of random velocities)
VE_random = randi(100,10,1);%(feet/second)east velocity
VD_random = randi(20,10,1);%(feet/second)down velocity
%generate random velocities for position extrapolation
%initial velocity
m = 10;
for i = 1:m
VN_array(i) = VN_random(i) %array of n random numbers
VE_array(i) = VE_random(i) %array of n random numbers
VD_array(i) = VD_random(i) %array of n random numbers
end
VN_array = VN_array'
VE_array = VE_array'
VD_array = VD_array'
%generate m iterations of LAT_3,LON_3,ALT_3
step = 1
m = 10
for array = i:step:m
%initial velocity
VN = VN_array(i);%(feet/second)north velocity
%VE = 0 ;%(feet/second)east velocity
%VD = 0 ;%(feet/second)down velocity
%call position extrapolation function
%[LAT_3,LON_3,ALT_3] = Position_Extrapolation(t_0,t_final,VN,VE,VD,LAT,LON,ALT)
[LAT_3,LON_3,ALT_3] = Position_Extrapolation(0,100,VN,0,0,pi/4,pi/4,10)
end
Above is an attached piece of code that generates the outputs LAT_3, LON_3 and ALT_3. These outputs (which are part of a function I called in the script (Posittion Extrapolation) are located inside of a for loop, which is designed to run the function through m iterations of the variable VN. The variable VN is an input variable of the function that I am attempting to run through the function m times and store these values as an array. How would I go about running the variable "VN" m times (as created by the random number generator) through the function "Position Extrapolation" and store them in an array?

Accepted Answer

Matt J
Matt J on 1 Aug 2022
Edited: Matt J on 1 Aug 2022
Perhaps as follows:
ivals=1:step:m;
J=numel(ivals);
[LAT_3,LON_3,ALT_3]=deal(nan(1,J));
for j = 1:J
i=ivals(j);
[LAT_3(i),LON_3(i),ALT_3(i)] = Position_Extrapolation(0,100,VN_array(i),0,0,pi/4,pi/4,10);
end
  1 Comment
Matthew Greene
Matthew Greene on 1 Aug 2022
Looks good. Thanks man. I appreicate it. I'll have to research some of these functions for future refernce, to better understand how you constructed this code

Sign in to comment.

More Answers (0)

Categories

Find more on Conway's Game of Life in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!