필터 지우기
필터 지우기

how to convert arrays inside my cell array into cells?

조회 수: 1 (최근 30일)
ilona
ilona 2013년 12월 29일
편집: Azzi Abdelmalek 2013년 12월 29일
if I have a cell array:
% code
cities =
'city1'
'city2'
'city3'
'city4'
'city5'
I want my cell to include cells that include the strings inside like that
% code
cities =
{1x1 cell}
{1x1 cell}
{1x1 cell}
{1x1 cell}
{1x1 cell}
for example in the 3rd cell inside my cell array there is
% code
{1x1 cell}% inside of it --> 'city3'
without using any kind of loop! (cause I can do it without any real problam with a loop)
  댓글 수: 2
Image Analyst
Image Analyst 2013년 12월 29일
Cells are complicated - why make it even more complicated than it needs to be? If you want you could have cells inside of cells inside of cells inside of cells. But why?
ilona
ilona 2013년 12월 29일
this is because I study Matlab in a University course and they want me to submit a structure that include cell arrays that include cell arrays... for no good reason other then showing us it is possible...

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 12월 29일
out = num2cell(cities)
  댓글 수: 3
Image Analyst
Image Analyst 2013년 12월 29일
I never would have thought something called num2cell would work on something that is not numbers, but surprisingly it does.
ilona
ilona 2013년 12월 29일
yes! it is very surprising he is a genius!

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

추가 답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 29일
편집: Azzi Abdelmalek 2013년 12월 29일
cities ={'city1'
'city2'
'city3'
'city4'
'city5'}
out=cellfun(@(x) {x},cities,'un',0)
out{3}
%or
out=cellfun(@cellstr,cities,'un',0)
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 29일
I don't know how to explain, maybe you should look at
doc cellfun
ilona
ilona 2013년 12월 29일
thanks!

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


Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 29일
out=regexp(cities,'.+','match')

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by