Clear Filters
Clear Filters

Plotting a line, but the line is like a piecewise function

2 views (last 30 days)
I am calculating Temperature when given altiude. For different values of h, the temperature will either fall under an equation or it will be a constant number. Is there a way to graph a continuous line that uses all of these segments? It is already showing a single point on the graph that is the h and calculated T value, I'd like that to show up on the graph as well.
function [h, a] = Temperature(T)
prompt = 'Altitude (m) ';
h = input(prompt);
if (h <= 11000)
T = (h - 44332.30769230768) / -153.84615384615378
elseif (h <= 25000)
T = 216.66
elseif (h <= 47000)
T = (h + 47220) / 333.3
elseif (h <= 53000)
T = 282.66
elseif (h <= 79000)
T = (h - 115813) / -222.2
elseif (h <= 90000)
T = 165.66
elseif (h <= 110000)
T = (h - 48585) / 250
end
plot(T, h, 'o')

Accepted Answer

Matt J
Matt J on 7 Feb 2022
hdata=linspace(0,110000,1000);
Tdata=arrayfun(@Temperature,hdata);
plot(hdata,Tdata, 'o')
function T = Temperature(h)
if (h <= 11000)
T = (h - 44332.30769230768) / -153.84615384615378;
elseif (h <= 25000)
T = 216.66;
elseif (h <= 47000)
T = (h + 47220) / 333.3;
elseif (h <= 53000)
T = 282.66;
elseif (h <= 79000)
T = (h - 115813) / -222.2;
elseif (h <= 90000)
T = 165.66;
elseif (h <= 110000)
T = (h - 48585) / 250;
end
end

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!