Converting Cell matrix to a Numeric Matrix
2 次查看(过去 30 天)
显示 更早的评论
I have a cell matrix as shoown below.
B={'2' '3' '5'; '4' '7' '2'; '7' '5' '2'}
B =
3×3 cell array
{'2'} {'3'} {'5'}
{'4'} {'7'} {'2'}
{'7'} {'5'} {'2'}
I want to convert it a numeric matrix like as follows:
A =
2 3 5
4 7 2
7 5 2
0 个评论
采纳的回答
Stephan
2021-5-12
编辑:Stephan
2021-5-12
B={'2' '3' '5'; '4' '7' '2'; '7' '5' '2'}
C = cellfun(@(x)str2double(x),B)
3 个评论
Stephen23
2021-5-12
Or, by simply reading the str2double documentation, you can easily have much much more efficient code:
B = {'2','3','5';'4','7','2';'7','5','2'};
M = str2double(B)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!