필터 지우기
필터 지우기

How to place contents into a specif cell index?

조회 수: 3 (최근 30일)
Mark Golberg
Mark Golberg 2017년 6월 13일
편집: Andrei Bobrov 2017년 6월 13일
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
Adam
Adam 2017년 6월 13일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 6월 13일
편집: Andrei Bobrov 2017년 6월 13일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by