Don't understand indexing statement from compiler
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
MY code is:
function mbd = spherical_mirror_aberr(fn,D )
%SPHERICAL_MIRROR_ABERR Summary of this function goes here
% Detailed explanation goes here
delta_x = 0.01;
Num_x=D/2/delta_x;
f = fn * D;
delta_theta = asin(delta_x/(2*f));
D_theta = asin(D/2/(2*f));
theta(0: delta_theta:D_theta);
Mult = 8*delta_x/D^2;
mbd =Mult*sum( 2*f*tan(2*(0:delta_theta:Dtheta))(1/cos(0:delta_theta:D_theta) -1));
end
The compiler is giving me a warning: "indexing must appear last in an index expression" What does this mean that I need to do. It affects the "mbd" variable equation.
댓글 수: 4
Please don't add comments as answers
DJ V comment posted as an answer moved here:
function mbd = spherical_mirror_aberr(fn,D )
%SPHERICAL_MIRROR_ABERR Summary of this function goes here
% Detailed explanation goes here
delta_x = 0.01;
Num_x=D/2/delta_x;
f = fn * D;
delta_theta = asin(delta_x/(2*f));
D_theta = asin(D/2/(2*f));
theta(0: delta_theta:D_theta);
Mult = 8*delta_x/D^2;
mbd =Mult*sum( (0:delatax:D/2)*2*f*tan(2*(0:delta_theta:Dtheta))(1/cos(0:delta_theta:D_theta) -1));
end
THe error still exists, but the above code at least includes X.
Guillaume
2016년 12월 2일
As per comments to Adam's answer, you're still missing a *.
Adam
2016년 12월 2일
Errors come with an error message, not just a line number usually.
답변 (2개)
sum( ... )( ... )
is not valid syntax in Matlab.
You can't chain together parenthesis is what that error is essentially sayiing. I don't really know what you are trying to do in the expression. Maybe you are just missing a * from between the ) and the (
댓글 수: 4
Guillaume
2016년 12월 2일
It's actually
tan( 2*(...) )( ... )
that is causing the problem. It does look like you're missing an operator.
I would recommend using more white spaces in your expression and if necessary continuing on the next line (with the ... operator). At the very least be consistent. The
longexpression -1
in particular, I find very bad style. Either use
longexpression - 1
or
longexpression-1
Also, the line
theta(0: delta_theta:D_theta);
does not do anything since the result of the indexing is not assigned anywhere or displayed.
Guillaume
2016년 12월 2일
Well, you're missing the * between 2*f*tan(2*theta) and (1/cos(theta)-1)
Image Analyst
2016년 12월 2일
Since your theta is actually an array of theta's, you'll need dot slash instead of slash: 1./cos(). You'll also need a dot * instead of * almost everywhere, for example tan() .* (1./cos)
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!