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 Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by