carloscc
carloscc

Reputation: 799

NaN returns matlab

I have the following code;

x = -12:1/32:12;
y = -12:1/32:12;
[X,Y] = meshgrid(x,y);

z = (sin(sqrt(X.^2+Y.^2)))/(sqrt(X.^2+Y.^2))

For some reason it always returns NaN and I don't get it if I make

z = (sin(sqrt(X.^2+Y.^2)))

I actually get numbers. What is the problem?

Upvotes: 0

Views: 42

Answers (1)

mpaskov
mpaskov

Reputation: 1264

Perhaps you are after:

z = (sin(sqrt(X.^2+Y.^2)))./(sqrt(X.^2+Y.^2));

which element-wise division rather than matrix division.

Upvotes: 2

Related Questions