cell array for loop assignment
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
1 Commento
Prateek Rai
il 18 Giu 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 .
Risposte (1)
Voss
il 14 Nov 2023
A = {rand(10,2),rand(10,2),rand(10,2),rand(10,2)}
nA = numel(A);
result = cell(2,nA);
for ii = 1:nA
result(:,ii) = {A{ii}(1:end/2,:); A{ii}(end/2+1:end,:)};
end
disp(result);
1 Commento
Dyuman Joshi
il 14 Nov 2023
An approach without loops -
A = {rand(10,2),rand(10,2),rand(10,2),rand(10,2)}
B = horzcat(A{:})
C = mat2cell(B, [5 5], [2 2 2 2])
%For verification
C{1}
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!