Subscript indices must either be real positive integers or logicals

I have this simple program code
%------------------------GPS data loading---------------------------------%
data = load('data/sorted_coord.dat');
%--------------------------fault parameter info---------------------------%
fault = load('data/fault.dat');
fa_lat = fault(:,2);
fa_lon = fault(:,3);
length = fault(:,5)*1000; %convert to meters
width = fault(:,6)*1000; %convert to meters
depth = fault(:,4)*1000; %convert to meters
dip = fault(:,8);
strike = fault(:,7);
ss = fault(:,10).*cosd(fault(:,9));
ds = fault(:,10).*sind(fault(:,9));
op = zeros(1,2)';
when I try to this command:
m = length(fa_lat);
then it will return error
Subscript indices must either be real positive integers or logicals.
does anyone has solution to resolve this error?

 Accepted Answer

You have a variable called 'length' that is over-riding the function.
Never name variables the same as a builtin function (or your own functions for that matter).
I assume by
m = length(fa_lat)
you wish to call the builtin 'length' function, but instead it is trying to index into your 'length' array.
Rename your length array to 'len' or something else that isn't a function name and it should work.
which myVariableName
will tell you if a function exists with the name you wish to use as a variable where obviously 'myVariableName' would be 'length' or 'size' or some other tempting sounding name for a variable!

Asked:

on 14 Nov 2014

Answered:

on 17 Nov 2014

Community Treasure Hunt

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

Start Hunting!