Error using plot Vectors must be the same length. [line 29 ERROR]
2 次查看(过去 30 天)
显示 更早的评论
function moleFractionA = antonie2molfraction(A,B,T,P);
A = [6.80896, 935.86, 238.73]; %1x3 array A is n-butane
B = [6.87024, 1168.72, 224.21]; %1x3 array B is n-hexane
T = [0:10:1000]; %celsius
P = 1125.09; %torr ~ 1.5 bar
PvaporA = zeros(1,11);
PvaporB = zeros(1,11);
liquidmoleFractionA = zeros(1,11);
vapormoleFractionA = zeros(1,11);
for i = 1:11
PvaporA(i) = 10 ^ (A(1)-(A(2)/(A(3)+T(i))));
PvaporB(i) = 10 ^ (B(1)-(B(2)/(B(3)+T(i))));
liquidmoleFractionA(i) = (P-PvaporB(i)) ./ (PvaporA(i)-PvaporB(i));
vapormoleFractionA(i) = PvaporA(i) .* liquidmoleFractionA(i) / P;
end
plot(liquidmoleFractionA, T)
hold on
plot(vapormoleFractionA, T)
hold off
xlabel('Mole Fraction of N-Butane')
ylabel('Temperature in Celsius')
title('N-Butane / N-Hexane TXY Diagram')
end
1 个评论
回答(1 个)
Jim Riggs
2023-1-23
编辑:Jim Riggs
2023-1-23
The two arguments to the 'plot' command must be the same size, e.g. 'liquidmoleFractionA' must have the same length as 'T'.
A good way to do this is to use the 'T' vector length to define the loop parameter;
npt = length(T)
PvaporA = zeros(1,npt);
... etc.
for i=1:npt
PvaporA(i) = 10 ^ (A(1)-(A(2)/(A(3)+T(i))));
... etc.
Now you simply define the vector 'T', and all of your other vectors will conform to it.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!