How to split cell array separated by ',' into double array?
5 次查看(过去 30 天)
显示 更早的评论
I have a cell array (2x1) as follows
'0,0,0,2,2,0.39,0.49'
'0,1,2,2,2,0.34,0.44'
I need to split it into double array (2x7) so the output be as follows
0 0 0 2 2 0.39 0.49
0 1 2 2 2 0.34 0.44
Is this possible? if yes? any suggestions please?
0 个评论
采纳的回答
Azzi Abdelmalek
2016-4-29
编辑:Azzi Abdelmalek
2016-4-29
a={'0,0,0,2,2,0.39,0.49'
'0,1,2,2,2,0.34,0.44'}
out=cell2mat(cellfun(@str2num,strrep(a,',',' '),'un',0))
更多回答(1 个)
dpb
2016-4-29
>> c={'0,0,0,2,2,0.39,0.49'
'0,1,2,2,2,0.34,0.44'};
>> str2num(char(c))
ans =
0 0 0 2.0000 2.0000 0.3900 0.4900
0 1.0000 2.0000 2.0000 2.0000 0.3400 0.4400
>>
3 个评论
dpb
2016-4-29
Intended to ask--how did you get such a format instead of the numeric values in the first place?
Tobias Bramminge
2019-10-1
Hi! I am using this solution now, but of some reason, a few of my rows are deleted with the function.
Anybody familier with this problem?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!