Haw can convert categories array to array of numeric or logical ?

I am creating a neural network in MATLAB,but i got this error
Error using nntraining.setup>setupPerWorker (line 96)
Targets T{1,1} is not numeric or logical.
outputFolder= fullfile(tempdir, '');
rootFolder = fullfile(outputFolder, '');
categories = {'2', '1', '0'};
imds = imageDatastore(fullfile(rootFolder, categories), 'LabelSource', 'foldernames');
numImageCategories = size(categories(imds.Labels),1); % get category labels
[trainingDS,validationDS] = splitEachLabel(imds,0.7,'randomize'); % generate training and validation set
LabelCnt = countEachLabel(imds); % load lable information
p=[];
t1=[];
[l,m]=size(trainingDS.Files);
for q=1:l
im1=readimage(trainingDS,q);
im=double( im1);
[r,c]=size(im)
p11=[];
for i=1:r
for j=1:c
p11=[p11;im(i,j,1)];
end
end
p=[p p11];
t1=[t1 trainingDS.Labels(q)];
t = categories(t);
end
% % % %% Multilayer backpropagation neural network
% % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
net=newff(minmax(p), [4096 5 1], {'logsig','logsig','logsig'}, 'traingdx');
[net,tr,Y,E,Pf,Af]=train(net,p,t);
net

10 commentaires

Try passing in categorical(t)
i got this error
Error using nntraining.setup>setupPerWorker (line 96)
Targets T is not a matrix or cell array.
when i use t=categories(t) i obtain t (1*147 cell)
Then do not use
categories = {'2', '1', '0'};
Use
categories = [2,1,0];
I can't change it because it uses to define each folder category.
Error using imageDatastore (line 125)
Cannot find files or folders matching: 'C:\Users\DELL\AppData\Local\Temp\'.
Error in clasifiersector (line 20)
imds = imageDatastore(fullfile(rootFolder, categories), 'LabelSource', 'foldernames');
Sigh. Then
t = char(categories(t(:))) - '0';
Unable to use a value of type 'cell' as an index.
Error in clasifiersector (line 83)
t = char(categories(t(:))) - '0';
Where do you assign to t to be able to use it in the line
t = categories(t);
? You have been building up t1 but not t.
I made a mistake in her writing, but nothing change .
t = categories(t1);
@Walter Roberson thank you sir ,i solved this problem.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by