Error using plot Vectors must be the same length. [line 29 ERROR]
조회 수: 1 (최근 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!