hi all y teachers,
i have a cell :
a = {{8x1cell} {14x1cell} {11x1cell} {23x1cell} {17x1cell} {8x1cell} {18x1cell} {14x1cell} {20x1cell} {28x1cell}}
i need to change the dimension of each cell to a fix number, say 50x1 cell. So each cell will have dimension 50x1, and i want the rest rows of the cell to be 0 or []
ex: take the 1st col of the cell, it's 8x1cell and i need it to be 50x1 with 42rows left to be zero or []
old 8x1cell = {'i'; 'need'; 'a'; 'glass'; 'of'; 'water'; 'right'; 'now'}
new 8x1cell = {{'i'; 'need'; 'a'; 'glass'; 'of'; 'water'; 'right'; 'now'; 0; 0; ... till row 50}
is there any possible way i can perform that? really need your helps, plzz! :(
thx,
Maya

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 10월 13일

2 개 추천

for k=1:length(a)
a{k}(end+1:50={[]}; %pad with []
%a{k}(end+1:50={0}; %pad with []
end

추가 답변 (2개)

Jan
Jan 2011년 10월 13일

1 개 추천

for k=1:length(a)
L = length(a{k});
a{k}(L+1:50) = {0};
end

댓글 수: 1

Javier
Javier 2020년 11월 17일
Hello there, lets say I have the cell array
1×6 cell array
{8791×1 double} {8782×1 double} {8802×1 double} {8795×1 double} {8806×1 double} {8791×1 double}
I need to change all of them to be
{8782×1 double}
So that I would have a 1×6 cell array where there is repeated {8782×1 double}

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

Rusmaya Luthfina
Rusmaya Luthfina 2011년 10월 14일

0 개 추천

Wuaaaaa,, its work! the answers you both give me are working exactly what i need,, i've just checked and it's so simple,, stupid me. sorry for bothering you with this low-level question.. :D
So many thanks for you Mr Simon and Mr Jiang.
Ouw,, may i asked 1 more low-level question?
Is it possible to make that cell array (a) as output in a function?? 'coz i need to call a function containing that cell as an output..
---Maya----

댓글 수: 5

Fangjun Jiang
Fangjun Jiang 2011년 10월 14일
The answer is yes. Treat it no differently than any other variable. Put it in the output argument.
Also, see update in my answer. It provided both ways to pad with zero or with [].
Rusmaya Luthfina
Rusmaya Luthfina 2011년 10월 17일
Thank you :D
Rusmaya Luthfina
Rusmaya Luthfina 2011년 10월 17일
excuse me, is ur code only works for cell of cell array? what about if i have cell of double array?
ex:
b = {[8x1double] [14x1double] ... soon}
i've implemented ur code and it's said error
for k=1:length(a)
a{k}(end+1:50={[]}; %pad with []
%a{k}(end+1:50={0}; %pad with []
end
error :Conversion to double from cell is not possible.
and for your 1st code
a{k}{N} = [];
error Cell contents assignment to a non-cell array object.
sorry for bothering u again..
Rusmaya Luthfina
Rusmaya Luthfina 2011년 10월 17일
i've already figure this out,, :D thx
Alexander Sidelev
Alexander Sidelev 2018년 4월 3일
What is the solution to your problem? I can't figure it out

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2011년 10월 13일

댓글:

2020년 11월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by