Parameter sweep without nested for loop
Mostra commenti meno recenti
The following parameter sweep has many nested loops. How can I eliminate the nested loops with linear indices, but be able to access the evaporation value afterward for parameter values of temperature=75, humidity=40, and windSpeed=5? (The arithmetic line is a placeholder for a more complex calculation, so I don't want to elimate loops entirely). I know there are existing examples but I am struggling with the basics.
temperature = 70:5:90;
humidity = 30:10:100;
windSpeed = [2 5 10 20];
for iT = 1:length(temperature)
for iH = 1:length(humidity)
for iW = 1:length(windSpeed)
% Simple arithmetic placeholder for a more complex function
evaporation(iT, iH, iW) = temperature(iT) + humidity(iH) - windSpeed(iW);
end
end
end
% Access evaporation for temperature=75, humidity=40, and windSpeed=5
evaporation(temperature==75, humidity==40, windSpeed==5)
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!