Search code examples
matlabindexingparfor

parfor Subscript indices must either be real positive integers or logicals


It is my first time use parfor, and I got this error Subscript indices must either be real positive integers or logicals. I can't find what's going wrong?

shape = zeros(nFile, 36);
parfor i = 1 : nFile
     if(i <= nFile1)
        imgName = strcat(query_folder1, query_pt1(i).name);
    else
        imgName = strcat(query_folder2, query_pt2(i-nFile1).name);
    end
    tic;
    img = imread(imgName);
    hist = edge_histogram(img, 24);
    fxt = fxt + toc;
    shape(i,:) = hist;
end

Solution

  • The problem is in line 6, i-nFile1 is below 0. You should probably change it to (nFile1-i+1), which is between 1 and nFile1.