Info

This question is closed. Reopen it to edit or answer.

Error using + Matrix dimensions must agree.

1 view (last 30 days)
Ho Cheong Cheng
Ho Cheong Cheng on 29 Apr 2017
Closed: MATLAB Answer Bot on 20 Aug 2021
My code is below:
switch ForcingFunction
case 1
%F=FcosOmegat
Theta=atan(2.*Z.*Omega_n*Omega./(Omega_n.^2-Omega^2));
X=Ft./sqrt((Omega_n.^2-Omega^2).^2+(2*Z.*Omega_n.*Omega).^2);
Phi=atan((Omega_d.*(x0-(X.*cos(Theta)))))./((v0+(x0-(X.*cos(Theta))).*Z.*Omega_n)-(Omega.*X.*sin(Theta))));
Phi(isnan(Phi<thresold & Phi>-thresold))=0;
A_UP=(x0-X.*cos(Theta));
A_DOWN=csc(Phi);
A_DOWN(A_DOWN<thresold & A_DOWN>thresold)=0;
A=A_UP./A_DOWN;
for n=1:3,
RT(n,:)=A(n)*exp(-Z(n).*Omega_n(n).*t).*sin(Omega_d(n).*t+Phi(n))+X(n).*cos(Omega*t-Theta(n));
end
Error using -
Matrix dimensions must agree.
Error in new>CalculatingEquations (line 1064)
Phi=atan((Omega_d.*(x0-(X.*cos(Theta)))))./((v0+(x0-(X.*cos(Theta))).*Z.*Omega_n)-(Omega.*X.*sin(Theta)));
Error in new>calc_button_Callback (line 874)
CalculatingEquations(hObject, eventdata, handles);
However I always got an error when calculating Phi in all cases but X and Theta are fine even case 2 and case 3 are similar to case 1.
In this case I am trying to calculating three RTs
Note that :
Omega_d,x0,X,Theta,v0,Z,Phi,A are and should be [3x1] matrices like [1;2;3]
t is time ,t=ti:interval:tf
Omega is a constant, for example 20
On the other hand, if I seperate the whole work from GUIDE program, ie just run the script the code is absolutely fine. I can get the correct results
  1 Comment
Walter Roberson
Walter Roberson on 29 Apr 2017
At the MATLAB command prompt give the command
dbstop if error
and run the program. When it stops, examine the size() of each of the variables.
v0 looks to me to be the most likely to be the unexpected size.

Answers (0)

Community Treasure Hunt

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

Start Hunting!