# "Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 51-by-1" appears from A(N-1, N-2) = aw; How to solve this? Not sure what it says... Maybe someone can help me?

1.123 views (last 30 days)
Commented: Walter Roberson on 19 May 2022
%Data Given
N = 51;
mu = 0.1; %Pa
dt = 0.01; %delta time
dr = 0.0002; %radius between the points
rho = 1000; %kg/m3
k = [0,0.1,0.25,0.5,0.85]; %time
R = 0.01; %m
[r] = d_gridpoint(R);
%Constant Break Down
q = (mu*dt)/(rho*dr^2);
p = (mu*dt)./(2*rho*r*dr);
e = (2*mu*dt)/(rho*dr^2);
aw = (q)-(p);
ap = (-(e)-1);
ae = (q)+(p);
%Replace the Constant Into General Equation
%Apply Boundary Condition To Form a Matrix
%Initialization
A=zeros(N-1);
for i=2:N-2
A(i,i)=ap;
A(i,i-1)=aw(i);
A(i,i+1)=ae(i);
end
%Neumann Boundary Condition
A(1,1)=ap;
A(1,2)=(2*mu*dt)./(rho*dr.^2);
%Dirichlet Boundary Condition
A(N-1,N-1)=ap;
A(N-1,N-2)=aw;

Walter Roberson on 24 Mar 2018
We can tell from the line A(i,i-1)=aw(i); that aw is a vector of length at least N-2 . But in the line A(N-1,N-2)=aw you are attempting to assign that vector into the single location A(N-1,N-2)

prince kumar on 12 Jun 2018
Edited: Walter Roberson on 12 Jun 2018
clear ALL; clc;
%%INITIAL DATA
k=5;
% number of plate finite element
q=30; % kN/m2
f1=0; % kN
L= 6; % m all span
dhole=0;
h=0.010; % m
% L/125<=umax(h)<= L/500
E=210e6; % kpa
v=0.3;
r= L/2;
rhole = dhole/2;
l=(r-rhole)/k;
% length of one FE
%b=1/2 'half' of FE;
% 1=[0.2;1;0.6;0.6;0.6]
ro1FE= [0 0.10 0.20];
% coordinate of 1st FE
ro2FE= [0.20 0.70 1.20];
% coordinate of 2nd FE
ro3FE= [1.20 1.50 1.80];
% coordinate of 3rd FE
ro4FE= [1.80 2.10 2.40];
% coordinate of 4th FE
ro5FE= [2.40 2.70 3];
% coordinate of 5th FE
roFE= [ro1FE;ro2FE;ro3FE;ro4FE;ro5FE];
%%compatibility matrix of displacement
C=zeros(5*k,16);
C(1:6,1:5)=eye(5);
C(7:12,7:11)=eye(6);
C(13:18,13:17)=eye(6);
C(19:24,19:23)=eye(6,5);
% Coefficient matrix of equilibrium equation
for i=1:k
AK= zeros(6);
Ak(1,1) = roFE(i,1);
Ak(2,1)= 1.5*roFE(i,1)/b(i)-1; Ak(2,2)=1;
Ak(2,2) = 1;
Ak(2,3)=-2*roFE(i,1)/b(i);
Ak(2,5)=roFE(i,1)/(2*b(i));
Ak(3,1)= -roFE(i,2)/b(i)+2;
Ak(3,2)= -5/6;
Ak(3,3)= 2*roFE(i,2)/b(i)-2;
Ak(3,4)= 2/3;
Ak(3,5)= -roFE(i,2)/b(i);
Ak(3,6)= 1/6;
Ak(4,1)= -roFE(i,2)/b(i);
Ak(4,2)= -1/6;
Ak(4,3)= 2*roFE(i,2)/b(i)+2;
Ak(4,4)= -2/3;
Ak(4,5)= -roFE(i,2)/b(i)-2;
Ak(4,6)= 5/6;
Ak(5,5)= -roFE(i,3);
Ak(6,1)= roFE(i,3)/(2*b(i));
Ak(6,3)= -2*roFE(i,3)/b(i);
Ak(6,5)= 1+1.5*roFE(i,3)/b(i);
Ak(6,6)= -1;
Ak=2*pi*Ak;
% create diangonal matrix A
A(6*i-5:6*i,6*i-5:6*i)=Ak;
end
A=C' *A;
A;
% coefficient of flexibility matrix
for i=1:k
d11=4*roFE(i,2)-3*b(i);
d12=-v*(4*roFE(i,2)-3*b(i));
d13=2*(roFE(i,2)-b(i));
d14=-2*v(roFE(i,2)-b(i));
d15=-roFE(i,2);
d16=v*roFE(i,2);
d22=4*(roFE(i,2)-3*b(i));
d23=-2*v*(roFE(i,2)-b(i));
d24=-2*(roFE(i,2)-b(i));
d25=v*roFE(i,2);
d26=-roFE(i,2);
d33=16*roFE(i,2);
d34=-16*v*roFE(i,2);
d35=2*(roFE(i,2)+b(i));
d36=-2*v(roFE(i,2)+b(i));
d44=16*roFE(i,2);
d45=-2*v(roFE(i,2)+b(i));
d46=2*(roFE(i,2)+b(i));
d55=4*(roFE(i,2)+3*b(i));
d56=v*(4*roFE(i,2)+3*b(i));
d66=4*(roFE(i,2)+3*b(i));
Dk=((2*pi*b)/(15*kk*(1-v*v)))*Dk;
D(6*i-5:6*i,6*i-5:6*i)=Dk;
end
% {F}={Fo}+{Fp}={Fo}+[C]'*{Fp}
% create vertical matrix Fo
Fo=zeros(21,1);
Fo(1)=m1*2*pi*roFE(1,1);
Fo(2)=f1*2*pi*roFE(1,1);
Fo(18)=f2*2*pi*roFE(5,1);
Fo(21)=m2*2*pi*roFE(5,3);
q=[0;q;q;0;0];
for i=1:k
Fk=2*pi*b(i)*q(i)/3*[3*roFE(i,2)-b(i);
3*roFE(i,2)+b(i)];
Fkp=[0;0;Fk;0;0];
% create vertical matrix Fp
Fp_(6*i-5:6*i,1)=Fkp;
end
Fp=C'*Fp;
F = Fo+Fp;
sizeF=size(F);
alfa=D^-1*A'*(A*D^-1*A')^-1;
beta=(A*D^-1*A')^-1;
M=alfa*F;
u=1e3*beta*F; % in mm
Mro=M(1:2:END);
Mfi=M(2:2:END);
un=u(1:4:END);
what is the issue here can anyone tell
error coming like
Unable to perform assignment because the size of the left side is 6-by-5 and the size of the right side is 5-by-5?
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 12 Jun 2018
You have
C(1:6,1:5)=eye(5);
the left side is 6 x 5. The right side is 5 x 5.
Perhaps you want
C(1:5,1:5)=eye(5);
C(6,1:5) = 0;

muhammad choudhry on 13 Nov 2019
Edited: Walter Roberson on 25 Mar 2022
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 2-by-1.
Error in crosscorrelation (line 53)
dpx(i,j) = xpeak1 - xgrid(i);
Does anyone know where I am goign wrong?
clear all;
clc;
close all;
%frame 1 and frame 2
[xmax,ymax]=size(imagea);
%windowsizes
wsize=[64,64];
w_width=wsize(1);
w_height=wsize(2);
%center points grid
xmin=w_width/2;
ymin=w_height/2;
xgrid=200:w_width/2:864;
ygrid=200:w_height/2:1696
%number of window in total
w_xcount = length (xgrid);
w_ycount = length (ygrid);
% these correspond to the range for "search" windows in image B
x_disp_max = w_width/2;
y_disp_max = w_height/2;
% for every window, first we have to "create" the test matrix in image A.
% then in image B, we have to correlate this test window around it's
% original position in A, the range is pre-determined. The point of maximum
% correlation corresponds to the final avg. displacement of that window
test_ima(w_width,w_height)=0;
test_imb(w_width+2*x_disp_max, w_height+2*y_disp_max) = 0;
dpx (w_xcount, w_ycount) = 0;
dpy (w_xcount, w_ycount) = 0;
xpeak1 = 0;
xpeak1 = 0;
%i, j are for the windows
%test_i and test_j are the test window to be
%extracted from image A
for i=1:(w_xcount)
for j=1:(w_ycount)
max_correlation = 0;
test_xmin = xgrid(i)-w_width/2;
test_xmax = xgrid(i)+w_width/2;
test_ymin = ygrid(j)-w_width/2;
test_ymax = ygrid(j)-w_width/2;
x_disp = 0;
y_disp = 0;
test_ima = imagea(test_xmin:test_xmax, test_ymin:test_ymax);
test_imb = imageb((test_xmin-x_disp_max):(test_xmax+x_disp_max),(test_ymin-y_disp_max):(test_ymax+y_disp_max));
correlation = normxcorr2(test_ima,test_imb);
[xpeak,ypeak] = find(correlation==max(correlation(:)));
%Re-scaling
xpeak1 = test_xmin + xpeak - wsize(1)/2 - x_disp_max;
ypeak1 = test_ymin + ypeak - wsize(2)/2 - y_disp_max;
dpx(i,j) = xpeak1 - xgrid(i);
dpy (i,j) = ypeak1 - ygrid(i);
end
end
%vector display
quiver (dpy,-dpx)

yusuf oyal on 11 Jan 2021
Edited: Walter Roberson on 25 Mar 2022
%CLEAR: Variables and command window in MATLAB
clc,clear
% INPUT: PHYSICAL PARAMETERS of MECHANISM (centemeter)
ab=24;bc=20;dc=15 ;bd=24;de=15;fl=17;fg=25;el=20;ag=40;
% INPUT: Maximum Iteration Number Nmax
Nmax=100;
% INPUT: INITIAL GUESS VALUES for th3 th4, th5, s and to respectively
x=[190*pi/180,110*pi/180,150*pi/180,31];
% INPUT: ERROR TOLERANCE
xe=0.001*abs(x);
% INPUT: SYSTEM INPUTS (th2,w2,al2)
dth=5*pi/360;
th2=(0*pi/180):dth:(360*pi/180);
w2=10*ones(1,length(th2));
al2=0*ones(1,length(th2));
%----------------------------------------------
xe=transpose(abs(xe));
kerr=1; %If kerr=1, results are not converged
%%
for k=1:1:length(th2)
for n=1:Nmax
%----------------------------------------------
th3(k)=x(1);th4(k)=x(2);th5(k)=x(3);s(k)=x(4);
% INPUT: JACOBIAN Matrix
J=zeros(4,4);
J(1,1)=-bc*sin(th3(k)); J(1,3)=-s*sin(th5(k)); J(1,4)=cos(th5(k));
J(2,1)=bc*cos(th3(k));J(2,3)=s*cos(th5(k));J(2,4)=sin(th5(k));
J(3,1)=dc*sin(th3(k)+(1.488));J(3,2)=-de*sin(th4(k));J(3,3)=-s*sin(th5(k));J(3,4)=cos(th5(k));
J(4,1)=-dc*cos(th3(k)+(1.488));J(4,2)=de*cos(th4(k));J(4,3)=s*cos(th5(k));J(4,4)=sin(th5(k));
% INPUT: Function f
f=zeros(4,1);
f(1,1)=-(-ab*cos(th2(k))+bc*cos(th3(k))+s*cos(th5(k))+ag);
f(2,1)=-(-ab*sin(th2(k))+bc*sin(th3(k))+s*sin(th5(k))-fg);
f(3,1)=-(de*cos(th4(k))-dc*cos(th3(k)+(1.488))+s*cos(th5(k))-el);
f(4,1)=-(de*sin(th4(k))-dc*sin(th3(k)+(1.488))+s*sin(th5(k))-fl);
%----------------------------------------------
eps=inv(J)*f;x=x+transpose(eps);
if abs(eps)<xe
kerr=0;break
end
end
if kerr==1
fprintf('error')
end
th3(k)=x(1);th4(k)=x(2);th5(k)=x(3);s(k)=x(4);
%---velocity---------------------------
fv(1,1)=-ab*w2(k)*sin(th2(k));
fv(2,1)=ab*w2(k)*cos(th2(k));
fv(3,1)=0;
fv(4,1)=0;
vel=inv(J)*fv;
w3(k)=vel(1);w4(k)=vel(2);w5(k)=vel(3);Vs(k)=vel(4);
%---acceleration---------------------------
fa(1,1)=(bd*al2(k)*cos(th2(k))+bd*w2(k)^2*cos(th2(k))-bc*w3(k)^2*cos(th3(k))-2*Vs*w5(k)*cos(th5(k))-s*w5(k)^2*cos(th5(k)));
fa(2,1)=(-bd*al2(k)*sin(th2(k))+bd*w2(k)^2*sin(th2(k))-bc*w3(k)^2*sin(th3(k))-2*Vs*w5(k)*sin(th5(k))-s*w5(k)^2*sin(th5(k)));
fa(3,1)=(-s*w5(k)^2*cos(th5(k))+dc*w3(k)^2*cos(th3(k))+(1.488))-de*w4(k)^2*cos(th4(k))-2*Vs*w5(k)*sin(th5(k));
fa(4,1)=(-s*w5(k)^2*sin(th5)+dc*w3(k)^2*sin(th3(k))+(1.488))-de*w4(k)^2*sin(th4(k))+2*Vs*w5(k)*cos(th5(k));
acc=inv(J)*fa;
al3(k)=acc(1);al4(k)=acc(2);
al5(k)=acc(3);als(k)=acc(4);
end
th2d=th2*180/pi;
th3d=th3*180/pi;
th4d=th4*180/pi;
th5d=th5*180/pi;
%--------Plots---------------
figure(1),
subplot(4,3,1),plot(th2d,th3d,'r','linewidth',2),xlabel('\theta_2 (^o)'),ylabel('\theta_3(^o)'),grid on;
subplot(4,3,2),plot(th2d,w3,'r','linewidth',2),xlabel('\theta_2 (^o)'),ylabel('\omega_3(r/s)'),grid on;
subplot(4,3,3),plot(th2d,al3,'r','linewidth',2),xlabel('\theta_2 (^o)'),ylabel('\alpha_3(r/s^2)'),grid on;
subplot(4,3,4),plot(th2d,th4d,'r','linewidth',2),xlabel('\theta_2(^o)'),ylabel('\theta_4 (^o)'),grid on;
subplot(4,3,5),plot(th2d,w4,'r','linewidth',2),xlabel('\theta_2(^o)'),ylabel('\omega_4 (r/s)'),grid on;
subplot(4,3,6),plot(th2d,al4,'r','linewidth',2),xlabel('\theta_2 (^o)'),ylabel('\alpha_4(r/s^2)'),grid on;
subplot(4,3,7),plot(th2d,th5d,'r','linewidth',2),xlabel('\theta_2 (^o)'),ylabel('\theta_5(^o)'),grid on;
subplot(4,3,8),plot(th2d,w5,'r','linewidth',2),xlabel('\theta_2 (^o)'),ylabel('\omega_5(r/s)'),grid on;
subplot(4,3,9),plot(th2d,al5,'r','linewidth',2),xlabel('\theta_2 (^o)'),ylabel('\alpha_5(r/s^2)'),grid on;
subplot(4,3,10),plot(th2d,s,'r','linewidth',2),xlabel('\theta_2 (^o)'),ylabel('\theta_6(^o)'),grid on;
subplot(4,3,11),plot(th2d,Vs,'r','linewidth',2),xlabel('\theta_2 (^o)'),ylabel('\omega_6(m/s)'),grid on;
subplot(4,3,12),plot(th2d,als,'r','linewidth',2),xlabel('\theta_2 (^o)'),ylabel('\alpha_6(m/s^2)'),grid on;
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 11 Jan 2021
th3(k)=x(1);th4(k)=x(2);th5(k)=x(3);s(k)=x(4);
s(k) is assigned to so s is a vector.
% INPUT: JACOBIAN Matrix
J=zeros(4,4);
J(1,1)=-bc*sin(th3(k)); J(1,3)=-s*sin(th5(k)); J(1,4)=cos(th5(k));
s is a vector so -s*sin(th5(k)) is a vector but the left side of the assignment J(1,3) only has room for a scalar.

image-pro on 20 Oct 2021
Edited: Walter Roberson on 25 Mar 2022
clc;
imshow(a);
[r,c]=size(a);
rs=input('No of row splitted');
cs=input('No of col splitted');
nr=floor(r/rs);
nc=floor(c/cs);
SA(rs,cs,nr*nc)=0;
z=1;
for i=1:nr
for j=1:nc
SA(:,:,z)=a(((i-1)*rs+1):rs*i,((j-1)*cs+1):cs*j);
z=z+1;
end
end
i want to split image in matrix but following error is showing please solve this problem.
Unable to perform assignment because the size of the left side is 50-by-50 and the size
of the right side is 2-by-2.
Error in p12 (line 15)
SA(:,:,z)=a(((i-1)*rs+1):rs*i,((j-1)*cs+1):cs*j);
Walter Roberson on 20 Oct 2021
I think you had an existing SA variable that you did not clear.
Remember that if you use functions then existing variables in the base workspace cannot interfere.

kevin harianto on 25 Mar 2022
Edited: Walter Roberson on 25 Mar 2022
Unable to perform assignment because the size of the left side is 1856-by-3 and the size of the right
side is 1856-by-1. I want to use the lidar labeler app for reading through the code using the ROI labels
error in:
image(:,:,4) = ptcloud.Intensity;
I = helperPointCloudToImage(pointCloud);
from Playing around from the example using different dataSets with importing the data from the link: https://github.com/olpotkin/Lidar-Obstacle-Detection/tree/master/src/sensors/data/pcd/data_2
classdef LidarSemanticSegmentation < lidar.labeler.AutomationAlgorithm
% LidarSemanticSegmentation Automation algorithm performs semantic
% segmentation in the point cloud.
% LidarSemanticSegmentation is an automation algorithm for segmenting
% a point cloud using SqueezeSegV2 semantic segmentation network
% which is trained on Pandaset data set.
%
% lidar.labeler.AutomationAlgorithm.
% Copyright 2021 The MathWorks, Inc.
% ----------------------------------------------------------------------
% Step 1: Define the required properties describing the algorithm. This
% includes Name, Description, and UserDirections.
properties(Constant)
% Name Algorithm Name
% Character vector specifying the name of the algorithm.
Name = 'Lidar Semantic Segmentation';
% Description Algorithm Description
% Character vector specifying the short description of the algorithm.
Description = 'Segment the point cloud using SqueezeSegV2 network.';
% UserDirections Algorithm Usage Directions
% Cell array of character vectors specifying directions for
% algorithm users to follow to use the algorithm.
UserDirections = {['ROI Label Definition Selection: select one of ' ...
'the ROI definitions to be labeled'], ...
'Run: Press RUN to run the automation algorithm. ', ...
['Review and Modify: Review automated labels over the interval ', ...
'using playback controls. Modify/delete/add ROIs that were not ' ...
'satisfactorily automated at this stage. If the results are ' ...
'satisfactory, click Accept to accept the automated labels.'], ...
['Accept/Cancel: If the results of automation are satisfactory, ' ...
'click Accept to accept all automated labels and return to ' ...
'manual labeling. If the results of automation are not ' ...
'without saving the automated labels.']};
end
% ---------------------------------------------------------------------
% Step 2: Define properties you want to use during the algorithm
% execution.
properties
% AllCategories
% AllCategories holds the default 'unlabelled', 'Vegetation',
% 'Buildings' categorical types.
AllCategories = {'unlabelled'};
% PretrainedNetwork
% PretrainedNetwork saves the pretrained SqueezeSegV2 network.
PretrainedNetwork
end
%----------------------------------------------------------------------
% Note: this method needs to be included for lidarLabeler app to
% recognize it as using pointcloud
methods (Static)
% This method is static to allow the apps to call it and check the
% signal type before instantiation. When users refresh the
% algorithm list, we can quickly check and discard algorithms for
% any signal that is not support in a given app.
function isValid = checkSignalType(signalType)
end
end
%----------------------------------------------------------------------
% Step 3: Define methods used for setting up the algorithm.
methods
function isValid = checkLabelDefinition(algObj, labelDef)
% Only Voxel ROI label definitions are valid for the Lidar
% semantic segmentation algorithm.
isValid = labelDef.Type == lidarLabelType.Voxel;
if isValid
algObj.AllCategories{end+1} = labelDef.Name;
end
end
% Is there one selected ROI Label definition to automate.
end
end
%----------------------------------------------------------------------
% Step 4: Specify algorithm execution. This controls what happens when
% the user presses RUN. Algorithm execution proceeds by first
% executing initialize on the first frame, followed by run on
% every frame, and terminate on the last frame.
methods
function initialize(algObj,~)
% Load the pretrained SqueezeSegV2 semantic segmentation network.
outputFolder = fullfile(tempdir, 'Pandaset');
% Store the network in the 'PretrainedNetwork' property of this object.
algObj.PretrainedNetwork = pretrainedSqueezeSeg.net;
end
function autoLabels = run(algObj, pointCloud)
% Setup categorical matrix with categories including
% 'Car', 'Truck', 'OtherVehicle', 'Pedestrian', 'RoadBarriers',
% and 'Signs'.
autoLabels = categorical(zeros(size(pointCloud.Location,1), size(pointCloud.Location,2)), ...
0:12,algObj.AllCategories);
% Convert the input point cloud to five channel image.
I = helperPointCloudToImage(pointCloud);
% Predict the segmentation result.
predictedResult = semanticseg(I, algObj.PretrainedNetwork);
autoLabels(:) = predictedResult;
%using this area we would be able to continuously update the latest file on
% sending the output towards the CAN Network or atleast ensure that the
% item is obtainable
% This area would work the best as it is the place where the
% lidar app will run every time.
%first we must
end
end
end
function image = helperPointCloudToImage(ptcloud)
% helperPointCloudToImage converts the point cloud to 5 channel image
image = ptcloud.Location;
image(:,:,4) = ptcloud.Intensity;
rangeData = iComputeRangeData(image(:,:,1),image(:,:,2),image(:,:,3));
image(:,:,5) = rangeData;
index = isnan(image);
image(index) = 0;
end
function rangeData = iComputeRangeData(xChannel,yChannel,zChannel)
rangeData = sqrt(xChannel.*xChannel+yChannel.*yChannel+zChannel.*zChannel);
end
Walter Roberson on 25 Mar 2022

Behzad Ranjbar on 10 May 2022
Edited: Walter Roberson on 10 May 2022
for i=1,node_x;1;
if (DFlag_us==1)
F(1,i)=u_s/u_inf;
else
F(1,i)=-uf_s*dy+F(2,i);
end
if (DFlag_vs==1)
G(1,i)=v_s/u_inf;
else
G(1,i)=-vf_s*dy+G(2,i);
end
if (DFlag_un==1)
F(node_y-1,i)=u_n/u_inf;
else
F(node_y-1,i)=uf_n*dy+F(node_y-2,i);
end
if (DFlag_vn==1)
G(node_y-1,i)=v_n/u_inf;
else
G(node_y-1,i)=vf_n*dy+G(node_y-2,i);
end
end
for i=1,node_y;1;
if (DFlag_uw==1)
F(i,1)=u_w/u_inf;
else
F(i,1)=-uf_w*dx+F(i,2);
end
if (DFlag_vw==1)
G(i,1)=v_w/u_inf;
else
G(i,1)=-vf_w*dx+G(i,2);
end
if (DFlag_ue==1)
F(i,node_x-1)=u_e/u_inf;
else
F(i,node_x-1)=uf_e*dx+F(i,node_x-2);
end
if (DFlag_ve==1)
G(i,node_x-1)=v_e/u_inf;
else
G(i,node_x-1)=vf_e*dx+G(i,node_x-2);
end
end
for i=2,node_x-1;1;
DF(:,i)=(F(:,i)-F(:,i-1))/dx;
end
for j=2,node_y-1;1;
DG(j,:)=(G(j,:)-G(j-1,:))/dy;
end
I am recieving this error. (Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 99-by-1.
Error in Final (line 375)
DF(:,i)=(F(:,i)-F(:,i-1))/dx; )
Would you help me on this please!
Walter Roberson on 11 May 2022
I suggest that you replace your calculation of DF and DG

Behzad Ranjbar on 11 May 2022
%setting up BC value for pressure after solving p
for i=1 : node_x : 1
if (DFlag_ps==1)
p(1,i)=2*p_s-p(1,i);
else
p(1,i)=-pf_s*dy+p(1,i);
end
if (DFlag_pn==1)
p(node_y,i)=2*pf_n-p(node_y-1,i);
else
p(node_y,i)=pf_n*dy+p(node_y-1,i);
end
end
for i=1 : node_y : 1
if (DFlag_pw==1)
p(i,1)=2*p_w-p(i,2);
else
p(i,1)=-pf_w*dx+p(i,2);
end
if (DFlag_pe==1)
p(i,node_x)=2*p_e-p(i,node_x-1);
else
p(i,node_x)=pf_e*dx+p(i,node_x-1);
end
end
Index in position 1 exceeds array bounds. Index must not exceed 1.
Error in Final (line 532)
p(node_y,i)=pf_n*dy+p(node_y-1,i);

Mustafa Batuhan Turaç on 19 May 2022
Unable to perform assignment because the size of the left side is 1-by-600 and the size of the right side is 1-by-100.
%Plot P-V diagram of a given substance using van der Waals 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 = 4.086; % ft3/lbmole
R = 10.732; % psi ft3/(lbmole-R)
% van der Waals Equation of State Constants
% for Propane
a = 54565.6;
b = 1.9639;
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.250 1.118 1.069 1.031 1.0049 0.999];
%van der Waals Equation
fvdWEOSp = @(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 i= 1:numel(T)
Tx = T(i);
Hx = H(i);
P(i,:) = fvdWEOSp(Tx,V,Hx);
end
% plot(V,P); xlim([0 1000]);
semilogx(V,P); xlim([1 100]);
ylim([0 1000]);
xlim([0 200]);
xlabel('Volume, ft^3');
ylabel('Pressure, psi');
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 19 May 2022
P = zeros(numel(T), numel(V), numel(H));
3d array
P(i,:) = fvdWEOSp(Tx,V,Hx);
being assigned to with only two indices.
Tx = T(i); Hx = H(i);
if T and H are always indexed at the same index, then does it make sense to use a 3d array?