Borrar filtros
Borrar filtros

I am getting an error that "array indices must be positive integers or logical values" How to solve?

2 visualizaciones (últimos 30 días)
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 curet (line 17)
imageDatasetLabel = get_im_label(imdir);
this is my error. How to solve this error?
  3 comentarios
Dennis
Dennis el 6 de Mzo. de 2019
The error states that one of your indices is not a positive integer. This could be j (impossible to tell without your code), but my guess is that there might be only one entry in name.
Shan Sha
Shan Sha el 6 de Mzo. de 2019
close all;clear all;clc
addpath('./helpfun');
imdir = './CURET/';
savedir = ['./_features/CURET']; % save features
mkdir_bo(savedir);
datadir = 'results'; % save classification accuracy
mkdir_bo(datadir);
%% feature extraction
sigmaSet = [1 2 4];
F = makeGDfilters(sigmaSet);
snr = 0; % here "0" only denotes "No noise"
K = 2;
C = 1;
Ls = 3;
Lr = 5;
imageDatasetLabel = get_im_label(imdir);
imageDatasetFeatPath = get_feature_path(savedir);
tic;
fprintf('\n..................extracting image descriptors\n')
calculate_LETRIST_features(imdir, savedir, 'png', F, sigmaSet, Ls, Lr, K, C, snr);
imageDatasetFeatPath = get_feature_path(savedir);
%% classification
trail = 100; % results averaged over 100 runs
trainnum = 46;% trainning number per class
imageDatasetfea = load_feature(imageDatasetFeatPath);
rand('state',0);
randn('state',0);
for i = 1:trail
% generate training and test partitions
indextrain = [];
indextest = [];
labelnum = unique(imageDatasetLabel);
for j = 1:length(labelnum)
index = find(imageDatasetLabel == j);
perm = randperm(length(index));
indextrain = [indextrain index(perm(1:trainnum))];
indextest = [indextest index(perm(trainnum+1:end))];
end
trainfeatures = imageDatasetfea(indextrain,:);
trainlabel = imageDatasetLabel(:,indextrain);
testfeatures = imageDatasetfea(indextest,:);
testlabel = imageDatasetLabel(:,indextest);
trainNum = size(trainfeatures,1);
testNum = size(testfeatures,1);
DM = zeros(testNum,trainNum);
for j=1:testNum
test = testfeatures(j,:);
DM(j,:) = distMATChiSquare(trainfeatures,test)';
end
% Nearest-neighborhood classifier
CP=ClassifyOnNN(DM,trainlabel,testlabel);
cp_avg(1,i) = CP;
clear trainfeatures testfeatures DM
end
disp(['Total running time is ' num2str(toc/60) ' mins']);
AP=mean(cp_avg)
save(['.\results\CURET_LETRIST.mat'], 'AP');

Iniciar sesión para comentar.

Respuestas (1)

KSSV
KSSV el 6 de Mzo. de 2019
Note that MATLAB accepts only non zero positive integers and logicals as indices. Else from these every thing throws error.
A = rand(10,1) ;
A(1) % no error
A(3) % no error
A(-1) % throws error
A(0) = % throews error
idx = A<0.5 ; % idx will be logical
A(idx) % no error
Check your code where and why the index is getting negative.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by