How do I fix the "Subscript indices must either be real positive integers or logicals" error?

If you have the vectors r'(t) and r''(t), how can you plot curvature, K(t)=[normofthecrossproductofr'(t)andr''(t)]/[(normofr'(t))^3]? I've defined the x,y, and z components of r'(t) separately and did the same with r''(t), then defined r'(t) and a vector with said components. I then took the cross product of r'(t) and r''(t) using the "cross" function, defining the result as crossprod. I then entered the following:
curvature= @(W3) norm(crossprod(W3),2)/(norm(rprime(W3),2).^3);
figure
plot(w,curvature(w));
I had previously defined w as linspace(0,1). W3 is just a variable. When I run the code, I get this error: "Subscript indices must either be real positive integers or logicals." Is this because some of the results of sin and cos are negative? (sin and cos are part of the x, y, and z components of both r'(t) and r''(t).)

Answers (1)

2 Comments

w=linspace(0,1);
W3 has no value. I've tried replacing W3 with w but I get the same error.
w3 will take on the value of w after it's passed in to your anonymous function. If you want to debug it, then convert it to a regular function so you can step into it and examine variables and program flow.

This question is closed.

Asked:

on 18 Sep 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!