필터 지우기
필터 지우기

How can i simultaneously reference in cells

조회 수: 1 (최근 30일)
Christos
Christos 2013년 1월 30일
I have a cell array, lets say C. Each cell contains a matrix.
For example lets say C is
C{1}=[1 2;3 4;5 6]
C{2}=[7 8;9 10;11 12]
How can I create a new cell array D, whose i-th element is a matrix consisted by the i-th transposed rows of all matrices in C?
Then D must be
D{1}=[1 7;2 8]
D{2}=[3 9;4 10]
D{3}=[5 11;6 12]
  댓글 수: 1
Image Analyst
Image Analyst 2013년 1월 30일
Why do you want the trouble of a cell array when just a normal numerical array would be so much easier?

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

채택된 답변

Kye Taylor
Kye Taylor 2013년 1월 30일
This is fun... you can try
C{1}=[1 2;3 4;5 6]
C{2}=[7 8;9 10;11 12]
g = @(j)[C{1}(j,:);C{2}(j,:)]'; % function handle
D = arrayfun(g,1:3,'UniformOutput',false); % awesome function

추가 답변 (1개)

Jan
Jan 2013년 1월 30일
편집: Jan 2013년 1월 30일
E = cat(3, C{:});
E = permute(E, [3,2,1]);
n = size(E, 3);
D = cell(1, n); % Faster than CELL2MAT:
for iD = 1:n
D{iD} = E(:, :, iD);
end
Sorry, I cannot test this currently.
But consider Image Analysts idea: When you operate on rectangulare numerical values, a double array is smarter and much more efficient than a cell.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by