Subscript indices must either be real positive integers or logicals???

1 view (last 30 days)
Hi,
Lately I'm getting this error with the following code, which was running well many times. The code stops on the second 'if', which compares the strings.
I've already checked on debugging mode if there's something wrong with the variables, but everything is ok...do you know how it could be possible? I've already restarted Matlab, but the result doesn't change. The Matlab version is R2010a.
Thank you so much!
filenames = './patch1.mat ./patch2.mat ./patch3.mat';
function Patches = ReadPatches(filenames);
if numel(filenames) > 0;
spaces = [0 findstr(filenames, ' ') length(filenames)+1];
for i = 1:length(spaces) - 1;
filename = filenames(spaces(i)+1:spaces(i+1)-1);
if filename(end-3:end) == '.msh'
[c, v] = msh2coords(filename);
elseif filename(end-3:end) == '.mat'
load(filename, 'c', 'v')
end
end
end

Accepted Answer

Walter Roberson
Walter Roberson on 3 May 2013
You should be using strcmp() to compare strings, not "=="
At the command line give the command
dbstop if error
and run until the problem occurs. When it does, please show length(filename)
  1 Comment
Letizia
Letizia on 5 May 2013
Thank you Walter! I have solved the problem thanks to the command suggested by you (it was a very silly mistake on variable 'filenames'...).
I'll keep it in mind!

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!