Effacer les filtres
Effacer les filtres

How to convert char data to num??

66 vues (au cours des 30 derniers jours)
saeeda saher
saeeda saher le 22 Juin 2018
I have .mat file which contains labels of my image dataset. These labels are numbers (0,1,2,3,4,5,6) but in mat file these are saved as characters ('0','1','2','3','4','5','6'). How to convert these chars to num??
% Features Extraction of Face based on HOG
clear;
testing=imageSet('Testing\','recursive'); % folder name of the database
K=1;
for i=1:size(testing,2 )
for j=1:testing(i).Count
Face=read(testing(i),j);
Face=imresize(Face, [48 48]);
HOG_Features=extractHOGFeatures(Face);
testingFeatures(K,:)=single(HOG_Features);
testinglabel{K}=testing(i).Description;
K=K+1;
end
persons{i}=testing(i).Description;
end
testinglabel=testinglabel';
csvwrite(' Testing.csv', testingFeatures)

Réponses (1)

Adam Danz
Adam Danz le 22 Juin 2018
In your example, "characters ('0','1','2','3','4','5','6')" it looks like the labels might be a cell array of strings. For example
c = {'1','2','3','4'};
If that's the case, you can use
d = str2double(c);
Here's the conversion if the labels are a single string of numbers.
% single string of numbers
c = '1 2 3 4 5';
d = str2double(strsplit(c));

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by