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
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Communications Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!