MATLAB Answers

How can i fix the error 'Index exceeds the number of array elements (51)'

11 views (last 30 days)
Neha Binish
Neha Binish on 6 Apr 2020
Commented: Neha Binish on 8 Apr 2020
x = [0:0.1:5];
y = sin(x)/x;
plot(x, y), xlabel('xi'), ylabel('Theta'), title('Solution to Lane Emden Equation'),
grid on, axis equal;ax = gca; ylabel = texlabel(y); xlabel = texlabel(x);
ax.XAxisLocation = 'origin'
ax.YAxisLocation = 'origin'
Index exceeds the number of array elements (51).

  0 Comments

Sign in to comment.

Accepted Answer

Birdman
Birdman on 6 Apr 2020
You need to apply elementwise division:
x = [0:0.1:5];
y = sin(x)./x;
plot(x, y), xlabel('xi'), ylabel('Theta'), title('Solution to Lane Emden Equation'),
grid on, axis equal;ax = gca; ylabel = texlabel(y); xlabel = texlabel(x);
ax.XAxisLocation = 'origin'
ax.YAxisLocation = 'origin'

More Answers (0)

Products