Creating a for loop that calls to a separate function script and collects outputs in vector
Ältere Kommentare anzeigen
I have a function file called AirProperties.m that takes an Altitude and Mach Number as input and spits out 7 characteristics of the air in a row vector.
What I want to do is create a script that passes a vector of Altitude and a vector of Mach Number (of any size n) through AirProperties.m and have the output collected in a vector (n rows by 7).
Here is where I struggle. I want to evaluate AirProperties at the first Altitude value and every Mach Number, then the next Altitude value at every Mach Number.
This is what I have and it's not much:
% Inputs of Altitudes and Mach Numbers
n = 100; % Number of values
Alts = linspace(0,100000,n); % 100 values
Machs = linspace(0.5,5,n); % 100 values
% initialize vector to collect results
Results = zeros(n,7); % = [alt Me ReL Ue Cfe kadm Ra] The variables in the output of AirProperties.m
for i = 1:n
Results(i,:) = AirProperties(Alts(i),Machs(i));
for j = 1:n
Results(j,:) = AirProperties(Alts(j),Machs(j));
end
end
In this scenario, with 100 altitude values and 100 mach number values the size of the output vector would be 10000 by 7.
It's been a while and I know I'm missing some for loop basics in my brain, but a nudge in the right direction would be appreciated.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!