Effacer les filtres
Effacer les filtres

How to place contents into a specif cell index?

3 vues (au cours des 30 derniers jours)
Mark Golberg
Mark Golberg le 13 Juin 2017
Modifié(e) : Andrei Bobrov le 13 Juin 2017
Hello, I'm having a syntex issue with cellfun (I think).
I have the following:
A = cell(1,2);
B = cell(1,2);
A(1,1) = {rand(3,4,5)};
B(1,1) = {rand(3,4)};
A(1,2) = {rand(3,4,5)};
B(1,2) = {rand(3,4)};
I'd like to go over each cell in A, and place there the corresponding cell B, at location A(:,:,3).
I'm guessing cellfun should be used, but I can't figure it out how to write correctly the syntax.
Help please, someone?
Thanks.
  1 commentaire
Adam
Adam le 13 Juin 2017
So you want to create a 3d cell array as the result?
cat( 3, A, B )
ought to do what you want if I understand correctly, though A(:,:,3) is a bit confusing.
You cannot use cellfun to resize an array - it will just operate over the elements in an array and give an output of the same size.

Connectez-vous pour commenter.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 13 Juin 2017
Modifié(e) : Andrei Bobrov le 13 Juin 2017
AA = cat(4,A{:});
AA(:,:,3,:) = cat(3,B{:});
A = squeeze(num2cell(AA,1:3));
or with loop for..end
for ii = 1:numel(A)
A{ii}(:,:,3) = B{ii};
end

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by