Filter löschen
Filter löschen

How to place contents into a specif cell index?

3 Ansichten (letzte 30 Tage)
Mark Golberg
Mark Golberg am 13 Jun. 2017
Bearbeitet: Andrei Bobrov am 13 Jun. 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 Kommentar
Adam
Adam am 13 Jun. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 13 Jun. 2017
Bearbeitet: Andrei Bobrov am 13 Jun. 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

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by