how to fill a 2D array using for loops with given ranges
Show older comments
so i am given a problem in which i have a range for speed and density and i need to create an mxn matrix that contains the values of the power, by varying the air speed in the range of 15 m/s < V < 35 m/s and the air density range of 1.11 kg/m3 < density < 1.29 kg/m3. the power is given by a formula between speed and density. but i don't know how to fill this particular array whose dimensions are 19 rows (for the density) by 21 columns (for the speed). any suggestions ? Below is my attempt to try and fill the array.
height = input('enter the height of the car in meters: ');
width = input('enter the width of the front of the car in meters: ');
frontal_area = height * width;
v = [15:35];
roh = [1.11:0.01:1.29];
k = 0;
l = 0;
p = [];
for k = 1:length(v)
for l = 1:length(roh)
p = 0.2 * roh(l) * v(k).^3 * frontal_area
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!