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

조회 수: 1 (최근 30일)
yasmin almashagbah
yasmin almashagbah 2020년 12월 8일
답변: Hritika Suneja 2020년 12월 31일
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
Ameer Hamza
Ameer Hamza 2020년 12월 10일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Hritika Suneja
Hritika Suneja 2020년 12월 31일
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

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by