Borrar filtros
Borrar filtros

How to place contents into a specif cell index?

3 visualizaciones (últimos 30 días)
Mark Golberg
Mark Golberg el 13 de Jun. de 2017
Editada: Andrei Bobrov el 13 de Jun. de 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 comentario
Adam
Adam el 13 de Jun. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 13 de Jun. de 2017
Editada: Andrei Bobrov el 13 de Jun. de 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

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by