How to fix this problem?

3 次查看(过去 30 天)
Mira le
Mira le 2019-12-12
评论: Mira le 2019-12-13
>> sitem
sitem =
1 2 3
>> U
U =
1×2 cell array
[1×2 double] [1×2 double]
U{1}
ans =
1 2
>> U{2}
ans =
2 3
I want to check each value of sitem if it contain in U an put them in F ={}
the output is F = { {1 2}, {{1 2 },{ 2 3 }}, {2 3} }
please help me
  2 个评论
Image Analyst
Image Analyst 2019-12-13
Have you read the FAQ on cell arrays: Click Here
So what you're saying is that F is a cell array with 3 cells in it. Each cell contains another cell array - a 1-by-2 cell array. And the cell in the second cell F{2} contains 2 cells, each of which is ALSO a cell array. And... well it just gets so complicated to describe so let's just run it and see what F really is:
F = { {1 2}, {{1 2 },{ 2 3 }}, {2 3} }
celldisp(F)
You'll see
F =
1×3 cell array
{1×2 cell} {1×2 cell} {1×2 cell}
F{1}{1} =
1
F{1}{2} =
2
F{2}{1}{1} =
1
F{2}{1}{2} =
2
F{2}{2}{1} =
2
F{2}{2}{2} =
3
F{3}{1} =
2
F{3}{2} =
3
Why on earth do you want that? Cell arrays of cell arrays of cell arrays nested three deep? What an absolute nightmare. Why don't you just use ismember() to see if some value is contained in the array you want to search?
Mira le
Mira le 2019-12-13
that not what I meant
I said before I have to check each value of sitem if it contains in U
for example;
a=1;
for i=1:length(sitem)
for j=1:length(U)
if ismember(sitem(i),U{j})
F{a } = [F U{j}];
end
end
a=a+1;
end

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

标签

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by