For-loop error: Unable to perform assignment because the left and right sides have a different number of elements

2 ビュー (過去 30 日間)
I am currently trying to calculate the different processen in a combustion engine. For that I so calculated the change of volume, pressure and temperature. I'm now trying to calculate the heatflow.
Vphi,pphi and Tphi are all 1x7201 doubles.
Using the function gives me the error "Unable to perform assignment because the left and right sides have a different number of elements." in the line "warmth(i) = warmth(i-1) + dQ;". After a lot of troubleshooting I can't get it to work as a function. If I use it as a normal script it works without a problem for some reason. I would really like to use it as a function though.
Any help is highly appreciated.
function warmth = Warmth(Vphi, pphi, Tphi)
global dk rs s n
c_m = (s * n)/ 30;
warmth = zeros(1,rs+1);
dQ = 0;
for i = 2:length(Vphi)
alpha = dk^(-0.22) * 0.013 * pphi(i)^0.8 * Tphi(i) * 6.18 * c_m;
A = Vphi(i)/(dk/2);
dQ = alpha * A * (Tphi(i)-Tphi(i-1));
warmth(i) = warmth(i-1) + dQ;
end
end
  2 件のコメント
Matt J
Matt J 2019 年 3 月 30 日
編集済み: Matt J 2019 年 3 月 30 日
This works fine
global dk rs s n
[Vphi, pphi, Tphi]=deal(rand(1,7201));
[dk s n]=deal(1);
rs=10;
warmth_output = Warmth(Vphi, pphi, Tphi)
function warmth = Warmth(Vphi, pphi, Tphi)
global dk rs s n
c_m = (s * n)/ 30;
warmth = zeros(1,rs+1);
dQ = 0;
for i = 2:length(Vphi)
alpha = dk^(-0.22) * 0.013 * pphi(i)^0.8 * Tphi(i) * 6.18 * c_m;
A = Vphi(i)/(dk/2);
dQ = alpha * A * (Tphi(i)-Tphi(i-1));
warmth(i) = warmth(i-1) + dQ;
end
end
Catalytic
Catalytic 2019 年 3 月 30 日
GLOBALS ?!?!?!??! Surely you must be joking.

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

回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by