Effacer les filtres
Effacer les filtres

How to fix this problem?

3 vues (au cours des 30 derniers jours)
Mira le
Mira le le 12 Déc 2019
Commenté : Mira le le 13 Déc 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 commentaires
Image Analyst
Image Analyst le 13 Déc 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 le 13 Déc 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

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by