Removing one set of curly brackets in a cell array

  • Follow


Is there a way of changing
{{[1,2]},{'ab'}} to {[1,2],'ab'}, without looking at cells individually, and without using a loop? I have a cell array about 1000 by 1000 to which I want to apply such an operation. The example I give is a 1 by 2 example.

Thanks
David
0
Reply David 9/8/2010 12:20:08 PM

"David Epstein" <David.Epstein.spam@remove.warwick.ac.uk> wrote in message <i67v1o$qra$1@fred.mathworks.com>...
> Is there a way of changing
> {{[1,2]},{'ab'}} to {[1,2],'ab'}, without looking at cells individually, and without using a loop? I have a cell array about 1000 by 1000 to which I want to apply such an operation. The example I give is a 1 by 2 example.
> 
> Thanks
> David

A = {{[1,2]},{'ab'}} 
A = 
    {1x1 cell}    {1x1 cell}

A = [A{:}]
A = 
    [1x2 double]    'ab'

Oleg
0
Reply Oleg 9/8/2010 12:33:06 PM


I suppose you want to preserve original size of the cell of cells, in which case Oleg's answer is not appropriate, because it works only for 1 by N cells

Do as following :

>> A = { {[1,2]},{'ab'}; {[3,4,5]},{'cde'}; {[6]},{'f'} }

A = 

    {1x1 cell}    {1x1 cell}
    {1x1 cell}    {1x1 cell}
    {1x1 cell}    {1x1 cell}

>> B = reshape([A{:}], size(A))

B = 

    [1x2 double]    'ab' 
    [1x3 double]    'cde'
    [         6]    'f'  
0
Reply Thomas 9/8/2010 1:12:04 PM

2 Replies
221 Views

(page loaded in 0.81 seconds)

Similiar Articles:








7/7/2012 11:59:47 AM


Reply: