How do I plot outside temperature versus time in Matlab?

Hello,
I'm not sure how to graph the following code in Matlab (Temperaure over 24 hour period should look sinusodal):
for t = 1:24
T(t,1) = (((Tmax - Tmin)/2)+((Tmax - Tmin)/2) * sin(((t - 9)/12)*Pi));
Thank you!

6 件のコメント

rough93
rough93 2019 年 9 月 25 日
Do you already have the temperature numbers in MATLAB? Or do you have to pull those numbers within the program.
Jessica Poulin
Jessica Poulin 2019 年 9 月 25 日
This is what I have associated to it:
Tmax = 310; %Maximum Temperature Occurring at 3pm (K)
Tmin = 298; %Minimum Temperature Occurring at 3am (K)
and t is time from 1 to 24 hours
rough93
rough93 2019 年 9 月 25 日
And you want to graph a sin wave between 1 and 24 with these max and min values? just an even sin wave without any data provided for the hours in between?
Jessica Poulin
Jessica Poulin 2019 年 9 月 25 日
ideally the graph would have the temperatures at every hour directly on it, but it will be used just to demonstrate temperature flucuations during the day and not for mathematical purposes.
rough93
rough93 2019 年 9 月 25 日
Gotcha! See my answer below. If you want to start from midnight instead of mid day, change the +3 to -9.
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 9 月 25 日
Where is temperature data to plot across time hours?

サインインしてコメントする。

回答 (2 件)

Kevin Phung
Kevin Phung 2019 年 9 月 25 日
編集済み: Kevin Phung 2019 年 9 月 25 日

0 投票

no for loop needed.
Tmax = 310;
Tmin = 298;
t=(1:24)'; % transposed if you want a column vs row
T = ((Tmax - Tmin)/2) + ((Tmax-Tmin)/2)*sin((t-9)/12*pi)
figure
plot(T)
rough93
rough93 2019 年 9 月 25 日
編集済み: rough93 2019 年 9 月 25 日

0 投票

clc; clear
Tmax = 310; % Maximum daily temperature (3pm)
Tmin = 298; % Minimum daily temperature (3am)
x = 1:24;
Graph = 12*sin(((x+3)*pi)/12);
plot(Graph)
This assumes you start at mid day.

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

2019 年 9 月 25 日

コメント済み:

2019 年 9 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by