Extract numberpairs separated by brackets contained in a cell array into numeric vectors
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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 Comments
Fangjun Jiang
on 24 Oct 2011
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
on 24 Oct 2011
Answers (1)
Fangjun Jiang
on 24 Oct 2011
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 Comment
Andreas
on 24 Oct 2011
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!