how to convert arrays inside my cell array into cells?
1 次查看(过去 30 天)
显示 更早的评论
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
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?
采纳的回答
Andrei Bobrov
2013-12-29
out = num2cell(cities)
3 个评论
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.
更多回答(2 个)
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!