Issue: Matrix Dimensions Must Agree

%PV=NRT
T1=273;
T2=293;
T3=313;
P=100:50:300; %kPa
R=8.314; %Ideal gas constant J*K^-1*mol^-1
n=1;
Volume1=n*R*T1/P;
Volume2=n*R*T2/P;
Volume3=n*R*T3/P;
figure(1)
plot(Volume1,P)
xlabel('Pressure [kPA]')
ylabel('Volume [m^3]')
figure(2)
plot(Volume2,P)
xlabel('Pressure [kPA]')
ylabel('Volume [m^3]')
figure(3)
plot(Volume3,P)
xlabel('Pressure [kPa]')
ylabel('Volume [m^3]')

답변 (1개)

James Tursa
James Tursa 2017년 9월 5일
편집: James Tursa 2017년 9월 5일

0 개 추천

Use element-wise operator ./ (with the dot) instead of the matrix operator /
E.g.,
Volume1=n*R*T1./P;
Volume2=n*R*T2./P;
Volume3=n*R*T3./P;

댓글 수: 2

Brandon Mello
Brandon Mello 2017년 9월 5일
In the plots generated, how would you vary the pressure between 100 kPa and 300 kPa in steps of 50 kPa?
James Tursa
James Tursa 2017년 9월 5일
편집: James Tursa 2017년 9월 5일
You've got the pressure and volume arguments reversed in your plot calls. The first one is the x-axis and the second one is the y-axis. So this line:
plot(Volume1,P)
should be this instead:
plot(P,Volume1)
Same for Volume2 and Volume3.
And if you want to change the tick spacing on the x-axis, you could do something like this for each figure:
set(gca,'Xtick',P);
Finally, I typically use this to make the plots more readable:
grid on

댓글을 달려면 로그인하십시오.

카테고리

제품

질문:

2017년 9월 5일

편집:

2017년 9월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by