Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Don't understand indexing statement from compiler

1 回表示 (過去 30 日間)
DJ V
DJ V 2016 年 12 月 2 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 件のコメント
DJ V
DJ V 2016 年 12 月 2 日
編集済み: DJ V 2016 年 12 月 2 日
I simplified the code considerably just to begin to find the error:
Now it produces:
Error in spherical_mirror_aberr (line 10)
mbd =Mult*sum( (0:delatax:D/2));
Adam
Adam 2016 年 12 月 2 日
Errors come with an error message, not just a line number usually.

回答 (2 件)

Adam
Adam 2016 年 12 月 2 日
編集済み: Adam 2016 年 12 月 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
Guillaume 2016 年 12 月 2 日
Well, you're missing the * between 2*f*tan(2*theta) and (1/cos(theta)-1)
Image Analyst
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)

DJ V
DJ V 2016 年 12 月 2 日
BUt in the code as written now there is no multiplication or division,and it still won't work.

Community Treasure Hunt

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

Start Hunting!

Translated by