From: Bruno Luong on
I0=['00' ;'01'; '10'; '11'];

[I J]=ndgrid(1:length(I0));
[I0(I(:),:) I0(J(:),:)]

ans =

0000
0100
1000
1100
0001
0101
1001
1101
0010
0110
1010
1110
0011
0111
1011
1111

% Bruno
From: Nathan on
On Apr 6, 2:29 pm, "Juliette Salexa" <juliette.physic...(a)gmail.com>
wrote:
> "james bejon" <jamesbe...(a)yahoo.co.uk> wrote in message
>
> Thanks James,
>
> I realized I messed up that example:
>
> It should have been:
>
> ['0000' ; '0100' ; '1000' ; '1100';
>  '0001' ; '0101' ; '1001' ; '1101';
>  '0010' ; '0110' ; '1010' ; '1110';
>  '0011' ; '0111' ; '1011' ; '1111']
>
> which should be kron(I0,I0),
>
> except, instead of multiplying the elements, I want to concatenate the strings.
>
> Your example with cell arrays was exactly what I want to do, but I was avoiding cell arrays because I don't want to get something like:
>
> k =
>
>     {1x1 cell}    {1x1 cell}    {1x1 cell}    {1x1 cell}
>     {1x1 cell}    {1x1 cell}    {1x1 cell}    {1x1 cell}
>     {1x1 cell}    {1x1 cell}    {1x1 cell}    {1x1 cell}
>     {1x1 cell}    {1x1 cell}    {1x1 cell}    {1x1 cell}
>
> instead, I want to be able to see the entries all simultaneously and easily

I believe your example output is still wrong.
Note that semicolons between elements in a matrix means separation by
rows.
Therefore, your matrix would end up being a 16x4, rather than a 4x16.

This may be excessive, but try this:
I0 = ['00';'01';'10';'11'];
I0c = mat2cell(I0,repmat(1,1,max(size(I0))),min(size(I0)));
k = cell2mat(cellfun(@(y)cell2mat(y),arrayfun(@(x)[repmat(x,size(I0c))
I0c],I0c,'uni',0),'uni',0));
%%%%%%%%%%%%%%%%%
k =
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

If you really wanted the 4x16 matrix, just add a transpose in there:
k = cell2mat(cellfun(@(y)cell2mat(y),arrayfun(@(x)[repmat(x,size(I0c))
I0c],I0c,'uni',0)','uni',0));
%%%%%%%%%%%%%%%%%
k =

0000010010001100
0001010110011101
0010011010101110
0011011110111111


A bit excessive,
Nathan
From: Juliette Salexa on
Thanks Bruno and Nathan!

Wow Bruno that was amazing! I didn't think of using ndgrid,

Thanks Nathan .. It's true that the answer to my original question should have been a 16x4, but my overall goal was to get the 4x16 that James gave me ... he must have read my mind!