Matlab for loop error with '>='
Ältere Kommentare anzeigen
Dear Matlab gurus,
Having trouble plotting several graphs using a for loop. Error comes upto '>='. Tried with '>' only, and it too won't work.
"Error: File: ******.m Line: 14 Column: 7 Unexpected MATLAB operator."
I'm not too good at computing. Help would be much appreciated.
Thanks,
Kelvin
% Drag force coefficient
c = 1.3
% Surface area of skydiver - m^2
A = 1.2
% Altitude - m
h = 40000
% Atmospheric pressure - Pa
p = 101325
% Specific gas constant for dry air - J/kg K
R = 287.058
% Density - mol
D = P/R.*T
for h >= 0
% Temperature - K
T = -1.033.*10.^-16.*h.^4 + 3.344.*10.^-12.*h.^3 + 2.521.*10.^7.*h.^2 - 0.009527.*h + 293;
% Pressure
P = p.*(1 - 2.256.*10.^-5.*h).^5.256;
% Drag Force
F = 1/2.*p.*v.^2.*c.*A;
h = h - 1;
end
% Q1
figure(1);
plot(T, h)
title('Temperature as a fn of Altitude')
xlabel('Temperature (K)')
ylabel('Height (m)')
% Q2
figure(2);
plot(P, h)
title('Pressure as a fn of Altitude')
xlabel('Pressure (Pa)')
ylabel('Height (m)')
% Q3
figure(3);
plot (D, h)
title('Density as a fn of Altitude')
xlabel('Density (mol.)')
ylabel('Height (m)')
Akzeptierte Antwort
Weitere Antworten (2)
John D'Errico
am 24 Sep. 2017
Bearbeitet: John D'Errico
am 24 Sep. 2017
for x >= 0
is not valid MATLAB syntax. No matter what you think it means, you cannot make up new syntax and expect it to work. Computer languages don't work that way.
Perhaps you wanted a while loop. But x is undefined at that point.
I'd start by reading the help docs on for and while. Reading the manual is always a good idea.
doc for
doc while
3 Kommentare
Kelvin Kong
am 24 Sep. 2017
Kelvin Kong
am 24 Sep. 2017
Image Analyst
am 24 Sep. 2017
Uh, no. What value can be both equal to zero and greater than zero at the same time? Anyway, (h=0) is an assignment, and that will probably return "true" since the assignment can be made successfully. But a for loop is
for k = startValue : stepValue : endingValue
or
for k = setOfKValues
where setOfKValues is a set of values that k will take on in turn as the loop iterates.
I'm thinking you probably want
while h > 0
Kelvin Kong
am 25 Sep. 2017
Kategorien
Mehr zu Programming 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!