norm() - Subscript indices must either be real positive integers or logicals.

2 views (last 30 days)
Hello everyone, I'm having trouble with my script. First off, this is the relevant code:
rawData = importdata('part1.csv', ';', 1);
data = rawData.data;
zeilen = size(data,1);
for i = 1:zeilen
LHuef=[data(i,3);data(i,4);data(i,5)];
RHuef=[data(i,6);data(i,7);data(i,8)];
MHuef=[data(i,9);data(i,10);data(i,11)];
LKnie=[data(i,12);data(i,13);data(i,14)];
RKnie=[data(i,18);data(i,19);data(i,20)];
ORueck=[data(i,30);data(i,31);data(i,32)];
LHuef1=[LHuef(2);LHuef(3)];
LKnie1=[LKnie(2);LKnie(3)];
ORueck1=[ORueck(2);ORueck(3)];
MHuef1=[MHuef(2);MHuef(3)];
RHuef1=[RHuef(2);RHuef(3)];
RKnie1=[RKnie(2);RKnie(3)];
HKL = (LHuef1 - LKnie1);
HR = (ORueck1 - MHuef1);
HKR = (RHuef1 - RKnie1);
dalphaL = acosd(abs(dot(HKL,HR))/(norm(HKL)*norm(HR)));
I'm getting this error:
Subscript indices must either be real positive integers or logicals.
Error in ExcelVariante (line 62)
dalphaL = acosd(abs(dot(HKL,HR))/(norm(HKL)*norm(HR)));
I tested a bit and found that "norm" doesn't seem to be working correctly here. The data is just x-y-z-coordinates, I set these vectors and calculate a lot of stuff with it. Including said angle-calculation which gives me back an error. If I set my vectors HKL, HR and HKR to fixed values it works. I have no clue why it does not work with my data matrix though.
If necessary I can provide more code, but I could not find anymore code relevant for the line causing my error.
Thanks in advance everyone.

Accepted Answer

Thorsten
Thorsten on 16 Sep 2015
Make sure that you have not used any of these as a variable
which norm
which abs
which acosd
which dot
  1 Comment
Jonas
Jonas on 16 Sep 2015
Oh my god thank you so much. Now I feel dumb though. I did have a variable called 'norm' that I didn't even use yet.

Sign in to comment.

More Answers (1)

Guillaume
Guillaume on 16 Sep 2015
Edited: Guillaume on 16 Sep 2015
Let's work backward from the error: "Subscript indices must either be real positive integers or logicals". What it's telling you is: you're trying to index a matrix, and the index is not integer or not positive. So why would matlab think you're trying to index a matrix in the line
dalphaL = acosd(abs(dot(HKL,HR))/(norm(HKL)*norm(HR)));
when it's not your intention? The only way it can think that is if it thinks that norm or dot or abs or acosd is a matrix. For matlab to think that, it must mean that one of them exists as a variable.
So find out where you've created a variable called norm, (or dot or abs or acosd) and rename it to something that does not shadow one of matlab's built-in functions.

Community Treasure Hunt

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

Start Hunting!