|
|
Removing one set of curly brackets in a cell array
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: collecting data in loops - comp.soft-sys.matlabYou need to use a cell array: c{i}=3Dfind(mat(:,4)=3D=3Di); Note the curly brackets. BTW, some gratuitous advice: Don't use i or j as indices. cell String array without apostrophes - comp.soft-sys.matlab ...changing size of array - comp.soft-sys.matlab Removing one set of curly brackets in a cell array - comp ... long vector to 20 vectors with 5 elements), without ... changing size of array - comp.soft-sys.matlabcell String array without apostrophes - comp.soft-sys.matlab ... changing size of array - comp.soft-sys.matlab Removing one set of curly brackets in a cell array - comp ... Error while evaluating TimerFCN for timer 'timer-1' - comp.soft ...... the name of the callback function in curly braces to create a cell array. ... Configure CQGAPI m_APIConfig.set ... Newsreader - MATLAB Central If i remove the ... Wired Home Automation - comp.home.automationNot on some set timers that would be hard for anyone ... and a sprinkler control valve, among the regular array ... Ave. Fresno CA, 93711 (559) 435-9068 (559) 905-2204 cell ... Cell Arrays :: Data Types (MATLAB Programming) - www.kxcad.net home... of square brackets [ ]. The curly braces are cell array ... to add or remove cells: A = cell ... sets of curly braces. The first set represents cell (1,2) of cell array A. MATLAB Programming/Cell Arrays - Wikibooks, open books for an open ...... arrays except that curly brackets are used instead of square brackets. array = [1, 2, 3; 4, 5, 6]; cell ... cell_array(1)=[]; % remove first element - resize cell_array(1 ... 7/7/2012 11:59:47 AM
|
|
|
|
|
|
|
|
|