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

2 Ansichten (letzte 30 Tage)
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 Kommentare
Matt J
Matt J am 30 Mär. 2019
Bearbeitet: Matt J am 30 Mär. 2019
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

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Communications Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by