Extract numberpairs separated by brackets contained in a cell array into numeric vectors
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
I have got a cell array like:
a{1,1} = ( 40 1) ( 41 1) ( 42 1) ( 44 1000) ( 45 11)
a{2,1} = ( 46 5)
a{3,1} = ( 47 30)
and I would like to receive 2 numeric vectors according to the number pairs:
b =[40;41;42;44;45;46;47] and
c =[1;1;1;1000;11;5;30]
Thank you in advance.
2 个评论
Fangjun Jiang
2011-10-24
Is the data in the cell array a string, such as a{1,1} = '( 40 1) ( 41 1) ( 42 1) ( 44 1000) ( 45 11)'?
Andreas
2011-10-24
回答(1 个)
Fangjun Jiang
2011-10-24
a{1,1} = '( 40 1) ( 41 1) ( 42 1) ( 44 1000) ( 45 11)';
a{2,1} = '( 46 5)';
a{3,1} = '( 47 30)';
b=sscanf([a{:}],'( %f %f) ');
c=reshape(b,2,[])'
c =
40 1
41 1
42 1
44 1000
45 11
46 5
47 30
1 个评论
Andreas
2011-10-24
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!