Error using semilogx Data cannot have more than 2 dimensions. Error in aaaa (line 39) semilogx(V,P); xlim([1 100]); HOW CAN I SOLVE THİS PROBLEM? PLEASE HELP ME

3 Ansichten (letzte 30 Tage)
%Plot P-V diagram of a given substance using peng-Robinson equation of states
%Substance properties are defined by the van der Waals constants and
%the critical properties.
clc; clear; close all;
Tc = 765.62; % R
Pc = 550.60; % psi
Vc = 0.0703; % ft3/lbmole
R = 10.732; % psi ft3/(lbmole-R)
% peng-Robinson Equation of State Constants
% for n-Butane
a = 54566;
b = 1.161;
V = linspace(b*1.2,40*Vc,100); % vector of volume
% temperature in F
T = [60 180 230 270 300 306];
T = T + 460; % temperature in R
H = [1.2501 1.1184 1.0692 1.0318 1.0049 0.9996];
% peng-Robinson Equation
fPRWEOSp = @(Tx,Vx,Hx)(R*Tx./(Vx-b)-a*Hx./(Vx.^2 + 2*Vx*b-b^2));
P = zeros(numel(T), numel(V), numel(H));
for j=1:numel(H)
for i= 1:numel(T)
Tx = T(i);
Hx = H(j);
P(i,:,j) = fPRWEOSp(Tx,V,Hx);
end
end
% plot(V,P); xlim([0 100]);
semilogx(V,P); xlim([1 100]);
ylim([0 800]);
xlabel('Volume, ft^3');
ylabel('Pressure, psi');
Error using semilogx
Data cannot have more than 2 dimensions.
Error in aaaa (line 39)
semilogx(V,P); xlim([1 100]);

Antworten (1)

Chetan
Chetan am 15 Sep. 2023
Hello Mustafa,
It appears that you are encountering an issue while plotting data with different temperatures and enthalpy using the "simlogx" function.
The error message "Data cannot have more than 2 dimensions" occurs because the "semilogx" function in MATLAB expects the input data to be two-dimensional.
In your code, the variable P has three dimensions
(numel(T) x numel(V) x numel(H)),
which causes the error. To resolve this issue and plot the P-V diagram for each temperature, you need to split the data and obtain a two-dimensional format.
This can be done by either squeezing the array or using a for loop for indexing.
To understand the working of the "squeeze" function and the "semilogx" function, I recommend reading the following articles:
By applying the appropriate method to convert your data to a two-dimensional format, you should be able to plot the P-V diagram successfully.
I hope these suggestions help you resolve the issue you are facing.

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by