Effacer les filtres
Effacer les filtres

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

5 vues (au cours des 30 derniers jours)
RetiredCheetoXI
RetiredCheetoXI le 7 Fév 2022
Réponse apportée : Matt J le 7 Fév 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')

Réponse acceptée

Matt J
Matt J le 7 Fév 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

Plus de réponses (0)

Tags

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by