How to fix this problem?

2 Ansichten (letzte 30 Tage)
Mira le
Mira le am 12 Dez. 2019
Kommentiert: Mira le am 13 Dez. 2019
>> 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 Kommentare
Image Analyst
Image Analyst am 13 Dez. 2019
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 am 13 Dez. 2019
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

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by