Output argument "T" (and maybe others) not assigned during call to "temp_alt" error
1 view (last 30 days)
Show older comments
I am using one function that calls using two others. Here are the functions.
-------------------------------------------------------------------------------------------
function mach_number=mach(V);
mach_number=(V.*10.^3)./(sqrt(1.40.*287.*(temp_alt(alt_velo(V)))));
end
-------------------------------------------------------------------------------------------
function alt=alt_velo(V);
alt=((.0389*V.^5)-(.8115*V.^4)+(6.537*V.^3)-(25.45*V.^2)+(53.425*V)+3.8234)*(10.^3);
end
-------------------------------------------------------------------------------------------
function T=temp_alt(h);
if (h >= 25000)
T=(-131.21+.00299.*h)+273.15;
elseif (11000 < h) & (h < 25000);
T=(-56.46+273.15);
elseif (h <= 11000);
T=(15.04-(.00649.*h))+273.15;
end
end
-------------------------------------------------------------------------------------------
The function mach works when I enter mach(1:1:10) in the command window but when I do mach(.001:.001:1) I get the error below, I do not understand why. Please help.
-------------------------------------------------------------------------------------------
Error in temp_alt (line 12)
if (h >= 25000)
Output argument "T" (and maybe others) not assigned during call to "temp_alt".
Error in mach (line 12)
mach_number=(V.*10.^3)./(sqrt(1.40.*287.*(temp_alt(alt_velo(V)))));
0 Comments
Accepted Answer
Walter Roberson
on 14 Sep 2015
Edited: Walter Roberson
on 14 Sep 2015
You are passing a vector in to temp_alt but you are treating the argument as if it is a scalar.
You should be using logical indexing rather than if/elseif/else
function T=temp_alt(h);
T = zeros(size(h), class(h));
idx1 = h >= 25000;
T(idx1) = (-131.21 + .00299.*h(idx1)) + 273.15;
idx2 = (11000 < h) & (h < 25000);
T(idx2) = -56.46 + 273.15;
idx3 = ~(idx1 | idx2);
T(idx3) = (15.04 - (.00649.*h(idx3))) + 273.15;
end
4 Comments
More Answers (0)
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!