MATLAB: How to solve “Unable to perform assignment because the indices on the left side are not compatible with the size of the right side” error

arrayindicesindices don't matchindices not compatibleMATLABmatrixmatrix arraymatrix manipulation

I am not understanding this indices error. Please, take a look at the code and help me with the solution. I have highlighted the line in the code in which the error is shown.
dis0=input('dis0=');
disd0=input('disd0=');
phi0=input('phi0=');
phid0=input('phid0=');
theta0=input('theta0=');
thetad0=input('thetad0=');
fmin=input('fmin=');
fmax=input('fmax=');
for f=fmin:fmax
tp=1/f;
dt=1/(25*f);
for i=0:dt:2*tp
t=i;
j=i+2;
f1=sin(2*pi*f*t);
f2=a*sin(2*pi*f*t);
f3=b*sin(2*pi*f*t);
F=[f1; f2; f3];
if i==0
% The error is shown in the below line.
x(j)=[dis0; phi0; theta0];
xd(j)=[disd0; phid0; thetad0];
xdd(j)=M\(F-(K*x(j))-(C*xd(j)));
else
break
end
x(j-1)=x(j)-(dt*xd(j))+(0.5*(dt^2)*xdd(j));
x(j+1)=((M/(dt^2))+(C/(2*dt)))\(F-(K-((2*M)/(dt^2)))*x(j)-((M/(dt^2))-(C/(2*dt)))*x(j-1));
end
end

Best Answer

x(j) is a single array element. You are trying to assign it 3 values, [dis0; phi0; theta0]. I'm unsure what the intent is, but one way to solve this is to specify row and column indices:
x(:,j)=[dis0; phi0; theta0];
You will need to double check everywhere you use x to take this change into account.