convert from cell array to vector

281 次查看(过去 30 天)
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

采纳的回答

Jan
Jan 2019-5-22
编辑:Jan 2019-5-22
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.

更多回答(0 个)

类别

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