Filling Cell Array with Empty value

조회 수: 10 (최근 30일)
Abi Waqas
Abi Waqas 2015년 11월 25일
댓글: Avinash Dass 2019년 2월 26일
Hi Everyone
I have cell arracy call Reults look like given below 4x1 cell
3x1 cell
4x1 cell
3x1 cell
4x1 cell
4x1 cell
4x1 cell
4x1 cell
4x1 cell
4x1 cell
5x1 cell
4x1 cell
4x1 cell
5x1 cell
I want to do the dimension equal of each cell by filling with empty value so that it becomes like 5x1 cell
5x1 cell
5x1 cell
5x1 cell ... and so on.
Can any one help ? It would be great to check if dimension of any cell in a cell called 'Result' is less than 5 say 4x1 make it 5x1 by inseting the empty value at last.
If the check is not possible it is fine to make every cell with in cell call 'Result' 5x1
Thanks in advance.

채택된 답변

Thorsten
Thorsten 2015년 11월 25일
편집: Thorsten 2015년 11월 25일
for i = 1:numel(Result)
[r, c]= size(Result{i});
assert(c == 1, 'Number of columns must be 1.')
if r < 5, Result{i}{5,1} = []; end
end
  댓글 수: 2
Abi Waqas
Abi Waqas 2015년 11월 26일
Dear
thanks for response, i found another solution. The solution you gave is right but was not suiting my problem.
Thanks alot :)
Avinash Dass
Avinash Dass 2019년 2월 26일
Dear Abi,
Can you provide me your solution ?
Thanks in advance.

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

추가 답변 (1개)

Stephen23
Stephen23 2015년 11월 25일
편집: Stephen23 2015년 11월 25일
As an alternative you can easily remove one level of the cell nesting:
V = {{0;1;2};{3;4;5;6};{7;8;9}};
for k = numel(V):-1:1
Z(1:numel(V{k}),k) = V{k};
end
This produces a cell array without other cells nested inside it, each column is one of the cells of the original array (swap the Z-indices to make this the rows):
>> Z
Z =
[0] [3] [7]
[1] [4] [8]
[2] [5] [9]
[] [6] []
It may be easier to access the contents:
>> Z(:,2)
ans =
[3]
[4]
[5]
[6]
  댓글 수: 1
Abi Waqas
Abi Waqas 2015년 11월 26일
thank you for the reponse :)
I have found someother solution for that

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

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by