フィルターのクリア

I keep getting ??? Error using ==> plus Matrix dimensions must agree. Error in ==> dewpoint at 6 f(T,RH)=((​a*T)./(b+T​))+log(RH/​100)

5 ビュー (過去 30 日間)
Michele  Thompson
Michele Thompson 2017 年 10 月 11 日
回答済み: Walter Roberson 2017 年 10 月 11 日
T=[20 25 30 35];
RH=30:10:100; %relative humidity percentages
[Td] = dewpoint(T,RH)
the function file is...
function [Td] = dewpoint(T,RH)
%dewpoint at varius temps and humidities
% Detailed explanation goes here
a=17.27;
b=237.7; % Celcius
f(T,RH)=((a*T)./(b+T))+log(RH/100);
Td=(b*f(T,RH))/(a-f(T,RH));

回答 (2 件)

Jacob Ward
Jacob Ward 2017 年 10 月 11 日
Your T has 4 elements (1x4) while your RH has 8 (1x8). When you try to add them together in your function, MATLAB doesn't know how to add these two matrices because they are not the same size.
Try changing the line defining RH to RH = 30:20:90 so that it has 4 elements like T and your problem should go away.
  1 件のコメント
Michele  Thompson
Michele Thompson 2017 年 10 月 11 日
I'm supposed to evaluate this function at intervals of 10, so I can't change the RH input. Could I use a for loop instead?

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


Walter Roberson
Walter Roberson 2017 年 10 月 11 日
Vectorize.
function [Td] = dewpoint(T,RH)
%dewpoint at varius temps and humidities
% Detailed explanation goes here
a = 17.27;
b = 237.7; % Celcius
[gT, gRH] = ndgrid(T, RH);
f = ((a*gT)./(b+gT))+log(gRH/100);
Td = (b*f) ./ (a-f);

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by