How to convert char data to num??

89 次查看(过去 30 天)
saeeda saher
saeeda saher 2018-6-22
回答: Adam Danz 2018-6-22
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)

回答(1 个)

Adam Danz
Adam Danz 2018-6-22
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));

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by