필터 지우기
필터 지우기

cell array in cell array

조회 수: 1 (최근 30일)
Takahiro
Takahiro 2021년 4월 6일
댓글: Takahiro 2021년 4월 6일
a=cell(10,1);
for n=1:10
a{n}=cell(3,1);
a{n}{1}=datestr( now() );
a{n}{2}=now();
a{n}{3}=n;
end
% OK
a{1}
{'06-Apr-2021 19:02:25'}
{[ 7.3825e+05]}
{[ 1]}
% OK
a{1}{1}
'06-Apr-2021 19:02:25'
% I would like to obtain by
b = a{1:10}{3}
1,2,,,,,,10 % array

채택된 답변

Stephen23
Stephen23 2021년 4월 6일
편집: Stephen23 2021년 4월 6일
If you really want to use inconvenient nested cell arrays, this will work with your example data:
b = [a{:}];
b = [b{3,:}]
b = 1×10
1 2 3 4 5 6 7 8 9 10
Note that using just one cell array (no nested cell arrays) makes this task simpler:
a = cell(10,3);
for n = 1:10
a{n,1} = datestr( now() );
a{n,2} = now();
a{n,3} = n;
end
a{1,1}
ans = '06-Apr-2021 10:59:13'
a{1,2}
ans = 7.3825e+05
b = [a{:,3}]
b = 1×10
1 2 3 4 5 6 7 8 9 10
  댓글 수: 1
Takahiro
Takahiro 2021년 4월 6일
Thanks a lot!
Your answer is what I wanted, since cell array a "inconvinient nested cell array" is given by another code.
The code you indicated worked well as I imaged.
In addition, It was good opetunity to learn about "comma-separated lists".

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

추가 답변 (1개)

KSSV
KSSV 2021년 4월 6일
n = length(a) ;
iwant = zeros(n,1) ;
for i = 1:n
iwant(i) = a{i}{3} ;
end
  댓글 수: 1
Takahiro
Takahiro 2021년 4월 6일
Thanks.
But this case, a is given.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by