cell array for loop assignment
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Prateek Rai
le 18 Juin 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 .
Réponses (1)
Voss
le 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 commentaire
Dyuman Joshi
le 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}
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!