Index exceeds the number of array elements (0).

조회 수: 1 (최근 30일)
BALPARTAP SINGH
BALPARTAP SINGH 2020년 12월 2일
댓글: KSSV 2020년 12월 2일
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?
  댓글 수: 1
KSSV
KSSV 2020년 12월 2일
cos(C)= cos(A)*cos(A_)+ sin(A)*sin(A_)*cos(B-B_);
The above line is not correct.

댓글을 달려면 로그인하십시오.

채택된 답변

VBBV
VBBV 2020년 12월 2일
편집: VBBV 2020년 12월 2일
%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
  댓글 수: 1
KSSV
KSSV 2020년 12월 2일
You have to consider the angle units in the above.... I don't understand why people are answering the same answer, once it answered.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
KSSV 2020년 12월 2일
As you are expecting the angle to be in degrees, you have to use sind, cosd. If you enter the angles in radians, then use sin, cos.
You need to use like this:
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);
cosC= cosd(A)*cosd(A_)+ sind(A)*sind(A_)*cosd(B-B_); % consider a different variable name cosC
sinC= sqrt( 1- (cosC)^2); % consider a different variable name sinC
if A == (90)
disp('2D random assembly')
O= 1/180 ;
J = integral2(@(A_,B_) O*sinC*sind(A_),0,180,0,180);
else
disp('3D random assemby')
O= 1/360 ;
J = integral2(@(A_,B_) O*sinC*sind(A_),0,180,0,180);
end

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by