MATLAB Answers

0

how to solve the error array indices must be positive indices or logical values.

Asked by Shan Sha on 12 Oct 2018
Latest activity Commented on by Shan Sha on 14 Oct 2018
the error i am getting: Array indices must be positive integers or logical values.
Error in get_im_label (line 14)
if ~strcmp(dataname(j).name(end-1:end),'db') % ËÎ
Error in demo_CURET (line 25)
imageDatasetLabel = get_im_label(imdir);
how to solve this? i have attached my code with this.

  3 Comments

What is the value of j at line 14 when the error occurs?
the value of j is 486 when the error occurs
how about (end-1:end), any possible that it is negative value (end-1)?

Sign in to comment.

3 Answers

Answer by Walter Roberson
on 12 Oct 2018
 Accepted Answer

Your directory contains a name that is one character long. For example your code is not accounting for the . entry you will find in most file systems.

  3 Comments

Some of your file might have only one character, so name(end-1:end) become name(0:1)

Sign in to comment.


Answer by Steven Lord
on 12 Oct 2018

If that section of code is intended to check that the file has the extension db, instead call fileparts on the filename then use isequal, strcmp, etc. to test if the third output matches .db.

  0 Comments

Sign in to comment.


Answer by Image Analyst
on 12 Oct 2018

Try this:
if endsWith(dataname(j).name,'db','IgnoreCase',true)
% filename ends with 'db'
else
% Filename does not end with 'db'
end
endsWith() requires R2016b or later.

  3 Comments

Then you should be ok. So replace all that complicated code of yours with the code I gave you.

Sign in to comment.