Filter löschen
Filter löschen

Index in position 1 is invalid. error after running multiple times

1 Ansicht (letzte 30 Tage)
yasmin almashagbah
yasmin almashagbah am 8 Dez. 2020
Beantwortet: Hritika Suneja am 31 Dez. 2020
I am trying to extract features from a dataset. the problem that after a group of images features extracted it is stoped by itself for example features are extracted for 20 images then for image 21 it gives this error
Index in position 1 is invalid. Array indices must be positive integers or logical values.
my code
clc;
clear all;
close all;
warning off;
imds=imageDatastore('E:\dataset test','IncludeSubFolders',true,'LabelSource','foldernames');
trainingFeatures=[];
trainingLabels=imds.Labels;
for i = 1:numel(imds.Files) % Read images using a for loop
img = readimage(imds,i);
trainingFeatures(i,:) = example(img);
end
the error
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in clipLine (line 85)
inter1 = points(ind,:);
Error in A (line 55)
edge = clipLine(LINE, BOX);
Error in example (line 40)
[lensV, lensF] =A(img,N,pxMin,calLen);
Error in Untitled2 (line 30)
trainingFeatures(i,:) = example(img);
  1 Kommentar
Ameer Hamza
Ameer Hamza am 10 Dez. 2020
The error is caused by a function you defined, 'clipLine'. Add a breakpoint in this code to see what is causing the value of 'ind' to become invalid: https://www.mathworks.com/help/matlab/matlab_prog/set-breakpoints.html

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Hritika Suneja
Hritika Suneja am 31 Dez. 2020
It's difficult to fix the error without seeing the complete code. However errors like ' Index in position 1 is invalid.' generlly occur because of some incorrect indexing in your code. It might happen that a wrong variable is being used to index an array. You can use the command mentioned below to debug these types of errors:
>>dbstop if error

Community Treasure Hunt

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

Start Hunting!

Translated by