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

1 visualización (últimos 30 días)
RetiredCheetoXI
RetiredCheetoXI el 7 de Feb. de 2022
Respondida: Matt J el 7 de Feb. de 2022
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')

Respuesta aceptada

Matt J
Matt J el 7 de Feb. de 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

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by