필터 지우기
필터 지우기

Filling up a matrix

조회 수: 2 (최근 30일)
Royvg94
Royvg94 2015년 9월 28일
댓글: Walter Roberson 2015년 9월 29일
I have an array of 69 x 1 cells. Every cell contains a matrix of either 12 x 1 or 13 x 1. I want Matlab to make a matrix of 13 x 69 and filling up the empty spaces of the 12 x 1 matrices by adding zero's.
Is this possible?
Thanks for the help!

답변 (2개)

James Tursa
James Tursa 2015년 9월 28일
How about a simple loop:
result = zeros(13,69);
for k=1:69
n = numel(mycellarray{k});
result(1:n,k) = mycellarray{k};
end
  댓글 수: 1
Royvg94
Royvg94 2015년 9월 29일
The output of this is a matrix with only zero's. I need the results from all matrices in the array, and the matrices with only 12 rows, need to be filled to 13 by adding a zero.

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


Walter Roberson
Walter Roberson 2015년 9월 29일
first13 = @(V) V(1:13);
result = cell2mat( cellfun(@(V) first13([V;0]), YourCellArray, 'Uniform', 0) );
If the cells can be variable size all the way from empty to 13, then use
first13([V;zeros(13,1)])
  댓글 수: 2
Royvg94
Royvg94 2015년 9월 29일
I think this is what i need, the only problem is that the output is in 1 column, and i need it to be 13 x 69...
Walter Roberson
Walter Roberson 2015년 9월 29일
result = cell2mat( cellfun(@(V) first13([V;0]), YourCellArray, 'Uniform', 0).' );

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by