convert from cell array to vector

283 vues (au cours des 30 derniers jours)
Daniel Boateng
Daniel Boateng le 22 Mai 2019
Modifié(e) : Jan le 22 Mai 2019
Please how do i convert a cell array like a ={'1','2','3','4','5','6','7','8','8'}; to be b = [1 2 3 4 5 6 7 8 8]. I tried the function cell2mat but it didnt give me b = [1 2 3 4 5 6 7 8 8].
Thanks

Réponse acceptée

Jan
Jan le 22 Mai 2019
Modifié(e) : Jan le 22 Mai 2019
a ={'1','2','3','4','5','6','7','8','8'};
n = str2double(a)
This can be faster under some conditions:
n = sscanf(sprintf('%s ', a{:}), '%d').'
cell2mat converts the cell array of char vectors to a char matrix. But this does not convert the char vectors to numbers.

Plus de réponses (0)

Catégories

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by