Non - Singleton Error Message

I'M TRYING TO RUN THE BELOW CODE,
aa = input('Please Input Lift Curve Slope in rad >');
T1 = (TTheta - RTheta)/((D/2)-Hr);
AR = D/Cr;
K = 1/(pi*e*AR);
WB = waitbar(0,'Please Wait.. Calculation In Progress');
for i = 1:3
waitbar(i/MaxV,WB)
for j = 1:2
omega(j) = 2*pi*j;
a = 0.2;
finish = 0;
add = 1;
while finish == 0
for k = 1:size(r1,2)
% Local Quantities Calculation
Loc(k) = r1(k);
VT(j,k) = omega(j)*Loc(k);
W2(i,j,k) = sqrt((i*(1+a))^2 + omega(j)^2*Loc(k)^2);
Phi(i,j,k) = atan((i*(1+a))/VT(j,k));
Alpha(i,j,k) = RTheta + T1*Loc(k) - rad2deg(Phi(i,j,k));
% Local Coefficient Calculations
CL(i,j,k) = aa*deg2rad(Alpha(i,j,k));
CD(i,j,k) = Cdo + K*CL(i,j,k)^2;
% Local Force Calculations
Lift(i,j,k) = 0.5*ro*W2(i,j,k)^2*Cr*aa*deg2rad(Alpha(i,j,k));
Drag(i,j,k) = 0.5*ro*W2(i,j,k)^2*Cr*CD(i,j,k);
Dt(i,j,k) = (Lift(i,j,k)*cos(Phi(i,j,k)))-(Drag(i,j,k)*sin(Phi(i,j,k)));
Dq(i,j,k) = (Lift(i,j,k)*sin(Phi(i,j,k)))+(Drag(i,j,k)*cos(Phi(i,j,k)));
Dpr(i,j,k) = Dq(i,j,k)*VT(j,k);
% Local Efficiency Calculation
eff(i,j,k) = Dt(i,j,k)*(i*(1 + a))/Dpr(i,j,k);
end
% Efficiency calculation
Thrust = sum(Dt,3)*rStep;
da = Thrust/(2*ro*Ar*i^2);
anew = (a + da)/2;
if (a - anew)<1e-10
finish = 1;
end
a = anew;
add = add + 1;
if add > 500
finish = 1;
end
end
Torque = sum(Dq,3)*rStep;
Pr = sum(Dpr,3)*rStep;
Eff = Thrust.*repmat((MinV:size(Thrust,1))',1,size(Thrust,2))./Pr;
AdvRatio(i,j) = i/(j*D);
end
end
BUT UNFORTUNATELY EVERY TIME I RUN THIS CODE I GET THIS (see below) ERROR MESSAGE,
?? Assignment has more non-singleton rhs dimensions than non-singleton
subscripts
Error in ==> BEMMT at 62
W2(i,j,k) = sqrt((i*(1+a))^2 + omega(j)^2*Loc(k)^2);
COULD SOMEONE CORRECT THIS FOR ME.
FURTHERMORE, ABOVE CODE IS A MODIFICATION OF THE BELOW CODE, WHERE I HAVE NESTED A WHILE LOOP IN A FOR LOOP.
THIS CODE WORKS FINE BUT WHEN I USE THE WHILE COMMAND (code at the top - modified code with while loop) I GET THE ABOVE ERROR.
aa = input('Please Input Lift Curve Slope in rad >');
T1 = (TTheta - RTheta)/((D/2)-Hr);
AR = D/Cr;
K = 1/(pi*e*AR);
WB = waitbar(0,'Please Wait.. Calculation In Progress');
for i = MinV:2:MaxV
waitbar(i/MaxV,WB)
for j = 1:4:40
omega(j) = 2*pi*j;
for k = 1:size(r1,2)
% Local Quantities Calculation
Loc(k)=r1(k);
VT(k) = omega(j)*Loc(k);
W2(i,j,k) = sqrt(i^2 + omega(j)^2*Loc(k)^2);
Phi(i,j,k) = atan(i/(omega(j)*Loc(k)));
Alpha(i,j,k) = RTheta + T1*Loc(k) - rad2deg(Phi(i,j,k));
% Local Coefficient Calculations
CL(i,j,k) = aa*deg2rad(Alpha(i,j,k));
CD(i,j,k) = Cdo + K*CL(i,j,k)^2;
% Local Force Calculations
Lift(i,j,k) = 0.5*ro*W2(i,j,k)^2*Cr*aa*deg2rad(Alpha(i,j,k));
Drag(i,j,k) = 0.5*ro*W2(i,j,k)^2*Cr*CD(i,j,k);
Dt(i,j,k) = (Lift(i,j,k)*cos(Phi(i,j,k)))-(Drag(i,j,k)*sin(Phi(i,j,k)));
Dq(i,j,k) = (Lift(i,j,k)*sin(Phi(i,j,k)))+(Drag(i,j,k)*cos(Phi(i,j,k)));
Dpr(i,j,k) = Dq(i,j,k)*omega(j)*Loc(k);
% Local Efficiency Calculation
eff(i,j,k) = Dt(i,j,k)*i/Dpr(i,j,k);
end
% Efficiency calculation
Thrust = sum(Dt,3)*rStep;
Torque = sum(Dq,3)*rStep;
Pr = sum(Dpr,3)*rStep;
Eff = Thrust.*repmat((MinV:size(Thrust,1))',1,size(Thrust,2))./Pr;
Adv.Ratio(i,j) = i/(j*D);
end
end

1 Comment

It is difficult to reproduce the error in your code because it is chock full of undefined variables. It would help if you could rewrite it so that it can be run after clearing the workspace.

Sign in to comment.

Answers (2)

You have
Thrust = sum(Dt,3)*rStep;
da = Thrust/(2*ro*Ar*i^2);
anew = (a + da)/2;
From this we deduce that Thrust is going to be a scalar for the first iteration of i and j, a row vector for the first iteration of i and further iterations of j, and a 2D matrix for all subsequent iterations of i. The sum is going to involve positions that get default initialized to 0 when i is greater than 1, as Dt is growing as i and j increase so Dt(2,1:4:40,:) are going to exist and be summed in before they are set to anything other than the 0 they get assigned when a matrix implicitly grows in size.
With Dt being a vector or matrix, da is going to be a vector or matrix, so anew will be as well. And you set a=anew so a will become a vector or matrix. And then you are in trouble with the "if" statement and in the assignment that is blowing up.
I note that "a" not being a scalar was exactly the problem I suggested in your previous version of the question, which you have now deleted. (That was the one where the source line reported as being in error did not match any line of code in what you had posted.)
Pathiraja
Pathiraja on 4 Jan 2012
Yes I had to delete it as it had only the first code not the modified one.
So 'a' should be a scalar not a row vector? Could you be able to suggest a way to get this code right. Apologise first of all I'm new to Matlab.

1 Comment

Please follow up on what I wrote about Dt growing as you execute, and about you making calculations on locations you have not initialized. When you have your code fixed so that you are always working with the same subset of information, it should be much clearer as to what you want "a" to mean and the sizes that it makes sense for "a" to be.

Sign in to comment.

Asked:

on 3 Jan 2012

Community Treasure Hunt

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

Start Hunting!