Store m iterations of a variable in for loop

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Matt J
Matt J il 1 Ago 2022
Modificato: Matt J il 1 Ago 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 Commento
Matthew Greene
Matthew Greene il 1 Ago 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Conway's Game of Life in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by