Borrar filtros
Borrar filtros

How to convert char data to num??

66 visualizaciones (últimos 30 días)
saeeda saher
saeeda saher el 22 de Jun. de 2018
Respondida: Adam Danz el 22 de Jun. de 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)

Respuestas (1)

Adam Danz
Adam Danz el 22 de Jun. de 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));

Categorías

Más información sobre Data Type Conversion 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