How to fix this problem?

조회 수: 1 (최근 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