# cell array for loop assignment

1 view (last 30 days)
Wang Jack on 12 May 2020
Commented: Prateek Rai on 18 Jun 2020
Here is some code
A1 is a 1*4cell array, I want got a 2*4 cell array, but non of those statement can do,
all I got is nesting cell array
anyone any idear?
A2={};
A1={rand(10,2),rand(10,2),rand(10,2),rand(10,2);}
for i=1:4
A2={A2;mat2cell(A{i},[5,5],2)};
A3{i}=mat2cell(A{i},[5,5],2);
A4{:,i}=mat2cell(A{i},[5,5],2);
A5{1,i}=mat2cell(A{i},[5,5],2);
end
A2={};
A={rand(10,2),rand(10,2),rand(10,2),rand(10,2),};
for i=1:4
A2={A2;mat2cell(A{i},[5,5])};
A3{i}=mat2cell(A{i},[5,5]);
A4{:,i}=mat2cell(A{i},[5,5]);
A5{1,i}=mat2cell(A{i},[5,5]);
end
Prateek Rai on 18 Jun 2020
As per my understanding, you are having a 1*4 cell array from which you want to get 2*4 cell array
You can do this by the following sample code :
Here is a sample code :
A2=cell(2,4);
A={rand(10,2),rand(10,2),rand(10,2),rand(10,2);}
for i=1:4
A2{1,i}=A{i};
A2{2,i}=[5,5]; % fill the data of your interest in new column
end
You can refer to the following documentation for more details .

### Categories

Find more on Cell Arrays in Help Center and File Exchange

R2015b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!