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 Comments

Is the data in the cell array a string, such as a{1,1} = '( 40 1) ( 41 1) ( 42 1) ( 44 1000) ( 45 11)'?

Answers (1)

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

This question is closed.

Asked:

on 24 Oct 2011

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!