MATLAB: Index exceeds the number of array elements (0).

exceedsindex

prompt= 'Enter theta1 value';
A = input(prompt);
prompt = 'Enter phi1 value';
B = input(prompt);
prompt= 'Enter theta2 value';
A_ = input(prompt);
prompt = 'Enter phi2 value';
B_= input(prompt);
cos(C)= cos(A)*cos(A_)+ sin(A)*sin(A_)*cos(B-B_);
sin(C)= sqrt( 1- (cos(C))^2);
if A == (90)
disp('2D random assembly')
O= 1/180 ;
J = integral2(@(A_,B_) O*sin(C)*sin(A_),0,180,0,180);
else
disp('3D random assemby')
O= 1/360 ;
J = integral2(@(A_,B_) O*sin(C)*sin(A_),0,180,0,180);
end
I am getting error(Index exceeds the number of array elements (0) ) in 10th line. Please explain why I am getting this error?

Best Answer

%true
prompt= 'Enter theta1 value';
A = input(prompt);
prompt = 'Enter phi1 value';
B = input(prompt);
prompt= 'Enter theta2 value';
A_ = input(prompt);
prompt = 'Enter phi2 value';
B_= input(prompt);
coC= cos(A)*cos(A_)+ sin(A)*sin(A_)*cos(B-B_);
siC= sqrt( 1- (coC.^2));
if A == (90)
disp('2D random assembly')
O= 1/180 ;
J = integral2(@(A_,B_) O*siC.*sin(A_),0,180,0,180);
else
disp('3D random assemby')
O= 1/360 ;
J = integral2(@(A_,B_) O*siC.*sin(A_),0,180,0,180);
end
You are using parenthesis with undefined index on left side. Try above