I have
A={[1,6,3,2],[3,5,6]};
all_el =[];
for i=1:length(A)
all_el(end)=A{i}
end
I want to have this result
all_ell=[1,2,3,5,6]

 采纳的回答

all_el = unique([A{:}]);

2 个评论

if A is
A={{[1,6,3,2]},{[3,5,6]}};
all_el = unique([A{:}]);
I have error
int_res = cellfun(@(x)[x{:}], A, 'UniformOutput', false);
all_el = unique([int_res{:}]);

请先登录,再进行评论。

更多回答(1 个)

Sriram Tadavarty
Sriram Tadavarty 2020-3-16
编辑:Sriram Tadavarty 2020-3-16

1 个投票

Hi there,
It is not pretty clear as what you wanted to do.
To get the desired output, perform the following:
A={[1,6,3,2],[3,5,6]};
% With for loops
all_el =[];
for i=1:length(A)
all_el=[A{i} all_el];
end
all_el = unique(all_el);
% Without for loops
all_el = unique([all_el{:}])
Hope this helps.
Regards,
Sriram

类别

在 帮助中心 和 File Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by