Receiving error vectors must be the same length when trying to plot.

1 回表示 (過去 30 日間)
Camille Forest
Camille Forest 2020 年 2 月 26 日
コメント済み: Camille Forest 2020 年 2 月 26 日
I'm trying to model Earth's surface temperature with the radiative forcing of CO2 changing through time. For years 1600-1744 (i called them 1:144 interms of t in my code) [CO2]is constant, in 1745-1953 (145:358 interms of t in my code) [C02] is increasing by 0.068%/year, in 1954-2100 (359:500 in terms of t in my code) [CO2] is increasing by 0.4%. I have a function that I'm referencing which calculates the change in atmospheric emissivity redulting from the change in [CO2].
my function I'm referencing:
function e = eps_atm(CO2)
e = 0.8*(1+(0.0541*log(CO2/280)));
end
%% CO2 variation Climate Model %%
%set up constants
so = 1360; %units = W/m2
albedo = 0.3; %units = none
sigma = 5.67*10^-8; %units = W/((m^2)*(K^4))
p = 997; %units = kg/m^3
cw= 4181; %units = J/(kg*K)
h = 100; %units = m3
a = 0.0514; %units = none
co2 = 280; %units = none
deltat = 31556700; %units = seconds
nsteps = 500; %nsteps from i.c.
T(1) = 250; %units = K
for t = 1:nsteps
hold on;
if t == 1:144
T(t+1)= (((1+eps_atm(280)/2)*((so*(1-albedo))/4)-(sigma*T(t)^4))/(p*cw*h))*deltat+T(t);
elseif t == 145:358
T(t+1)= (((1+eps_atm(280*(1+0.00068*((t)-143)))/2)*((so*(1-albedo))/4)-(sigma*T(t)^4))/(p*cw*h))*deltat+T(t);
elseif t == 359:500
T(t+1)= (((1+eps_atm(280*(1+0.004*((t)-357)))/2)*((so*(1-albedo))/4)-(sigma*T(t)^4))/(p*cw*h))*deltat+T(t);
end
end
figure(1)
hold on;
time = [1:nsteps+1]*deltat;
plot(time/31556700, T,'x')

採用された回答

Jeremy
Jeremy 2020 年 2 月 26 日
T is 1x1 because none of your if statements are ever true. You want
if t <= 144
%do things
elseif t > 144 && t <= 358
%do different things
elseif t > 358
%do other, different things
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStress and Strain についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by