From: Alberto on
I am not sure if this is the right forum so please feel free to move.
Here is my question:
Lets imagine I have a variable people that is a Cell Array of names and ages:

people = {'Mr Joe Shmoe 34', 'Mrs Who Ha 30', 'Dr Jim Jam 58' 'Ms Twinky Pinky 7'}'

So in the command window, people will look like:
people =

'Mr Joe Shmoe 34'
'Mrs Who Ha 30'
'Dr Jim Jam 58'
'Ms Twinky Pinky 7'

If I want to split the cell so that I know the first part is the personTitle, second is firstName, third is surName, and last item is the their age, I could construct a new variable

step1 = regexp(people, ' ', 'split');

this returns a new <4x1 Cell>
step1 =

{1x3 cell}
{1x3 cell}
{1x3 cell}
{1x3 cell}

Now my question is how do I "reshape" this variable step1 to create a new variable step2 which is a cell of dimension <4x4> so that the first column is the personTitle, the second colum is the firstName, etc...

Many thanks and kind regards,
Alberto
From: Matt Fig on
Leaving aside the inconsistency in your example, one solution:

% Data
people = {'Mr Joe Shmoe 34', 'Mrs Who Ha 30', 'Dr Jim Jam 58' 'Ms Twinky Pinky 7'}'
step1 = regexp(people, ' ', 'split');

% Engine
reshape([step1{:}],4,4).'
From: Matt Fig on
Another, perhaps simpler:

cat(1,step1{:})
From: Alberto on
Ooopppss. I modified the variable people by appending their ages to make the example a little more complex. Thanks for the answer, your solution indeed gets me what I want.

Your suggestion produces:

>> reshape([step1{:}],4,4).'

ans =

'Mr' 'Joe' 'Shmoe' '34'
'Mrs' 'Who' 'Ha' '30'
'Dr' 'Jim' 'Jam' '58'
'Ms' 'Twinky' 'Pinky' '7'

This is exactly what I need, I am interest to know why you have used the dot operator before the transpose as it seems a little redundant to the novice user? I found this very tricky and thanks for your solution...
From: Matt Fig on
"Alberto " <andradefraga(a)googlemail5characters.com> wrote in message <i3f77s$8df$1(a)fred.mathworks.com>...
> Ooopppss. I modified the variable people by appending their ages to make the example a little more complex. Thanks for the answer, your solution indeed gets me what I want.
>
> Your suggestion produces:
>
> >> reshape([step1{:}],4,4).'
>
> ans =
>
> 'Mr' 'Joe' 'Shmoe' '34'
> 'Mrs' 'Who' 'Ha' '30'
> 'Dr' 'Jim' 'Jam' '58'
> 'Ms' 'Twinky' 'Pinky' '7'
>
> This is exactly what I need, I am interest to know why you have used the dot operator before the transpose as it seems a little redundant to the novice user? I found this very tricky and thanks for your solution...

Actually I like the second solution better, but in answer to your question, the .' is differentiated from the complex conjugate transpose operator which doesn't have the dot.