From: ade77 on
Nathan <ngreco32(a)gmail.com> wrote in message <3df75fac-9df3-4470-95be-f587dd8b4492(a)r5g2000yqb.googlegroups.com>...
> On Jan 8, 12:04 pm, "ade77 " <ade1...(a)gmail.com> wrote:
> > Example I have the array :
> > A = [ 1 2 3; 4 5 6; 7 8 9]
> >
> > I want a cell array of 3 by 1:
> > MyCell = {1 2 3
> >               4 5 6
> >               7 8 9}
> >
> > Meaning, I have an array of m by n, and I want my cell array to be m by 1
>
> You wrote that wrong, then. If you execute the code you supplied for
> MyCell, you will receive a 3x3 cell array.
> If you wanted [1 2 3] to be the first row and consist of only one
> column, you need to write it as such:
> MyCell = {[1 2 3];[4 5 6];[7 8 9]}
> %%%%%%%%%%%%%%%%%%%%%
> whos MyCell
> Name Size Bytes Class Attributes
> MyCell 3x1 252 cell
>
> Anyways...
> One way to do so is as follows:
> for i=1:size(A,1)
> MyCell(i,1) = {A(i,:)};
> end
> %%%%%%%%%%%%%%%%%%%%%
> whos MyCell
> Name Size Bytes Class Attributes
> MyCell 3x1 252 cell
>
> It probably isn't the most efficient way, but it works.
>
> -Nathan

thanks for all the reply.
In reality, my example was just a simple idea, what I actually have is a char array of 67000 rows, and 20 columns.

Each row contains a full name string.

Example:

Like my_char_array = john scott
jame canon
Lind david
so let us say I have the above array of rows 67000, and 10 columns, so my cell array will be :
my_cell_array = {'john scott'
'jame canon'
'Lind david'}

I was trying to avoid a for loop before, but I guess I have to use it.
From: Jan Simon on
Dear Ade77!

> In reality, my example was just a simple idea, what I actually have is a char array of 67000 rows, and 20 columns.
>
> Each row contains a full name string.
>
> Like my_char_array = john scott
> jame canon
> Lind david
> so let us say I have the above array of rows 67000, and 10 columns, so my cell array will be :
> my_cell_array = {'john scott'
> 'jame canon'
> 'Lind david'}

Do you mean CELLSTR ?
Jan
From: Matt Fig on
Asking the direct question will often avoid much runaround.


my_char_array = ['john scott'
'jame canon'
'Lind david']
my_cell_array = cellstr(my_char_array)
From: ade77 on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hi868s$961$1(a)fred.mathworks.com>...
> Dear Ade77!
>
> > In reality, my example was just a simple idea, what I actually have is a char array of 67000 rows, and 20 columns.
> >
> > Each row contains a full name string.
> >
> > Like my_char_array = john scott
> > jame canon
> > Lind david
> > so let us say I have the above array of rows 67000, and 10 columns, so my cell array will be :
> > my_cell_array = {'john scott'
> > 'jame canon'
> > 'Lind david'}
>
> Do you mean CELLSTR ?
> Jan


I am very sorry for putting all of you through this. That is exactly what I need, I forgot that function cellstr exist.

I appreciate all the replies.