Store m iterations of a variable in for loop

조회 수: 1 (최근 30일)
Matthew Greene
Matthew Greene 2022년 8월 1일
댓글: Matthew Greene 2022년 8월 1일
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?

채택된 답변

Matt J
Matt J 2022년 8월 1일
편집: Matt J 2022년 8월 1일
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
Matthew Greene
Matthew Greene 2022년 8월 1일
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

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conway's Game of Life에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by