5 views (last 30 days)

>> lambda = 1;

>> phi = zero;

Undefined function or variable 'zero'.

>> phi = 0;

>> theta = 90;

>> B= 2*pi/lambda;

>> Lx = 20*lambda;

>> Ly = 10*lambda;

>> u = sin(theta);

>> v = 0;

>> f(u,v) = (sin((B*Lx)*u)/((B*Lx/2)*u))*(sin((B*Ly)*v)/((B*Ly/2)*v));

Index in position

1 is invalid. Array indices must be positive integers or logical values.

Hi,

After I try to get values to f(u,v) .I got this error

Index in position

1 is invalid. Array indices must be positive integers or logical values.

Could you please help solve this problem?

James Tursa
on 10 Mar 2020

If you are trying to create an anonymous function, the syntax is:

f = @(u,v) (sin((B*Lx)*u)/((B*Lx/2)*u))*(sin((B*Ly)*v)/((B*Ly/2)*v));

Then downstream in your code you can call f(u,v) with arbitrary u and v inputs.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/510117-index-in-position-1-is-invalid-array-indices-must-be-positive-integers-or-logical-values#comment_808075

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/510117-index-in-position-1-is-invalid-array-indices-must-be-positive-integers-or-logical-values#comment_808075

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/510117-index-in-position-1-is-invalid-array-indices-must-be-positive-integers-or-logical-values#comment_808076

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/510117-index-in-position-1-is-invalid-array-indices-must-be-positive-integers-or-logical-values#comment_808076

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/510117-index-in-position-1-is-invalid-array-indices-must-be-positive-integers-or-logical-values#comment_808078

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/510117-index-in-position-1-is-invalid-array-indices-must-be-positive-integers-or-logical-values#comment_808078

Sign in to comment.