How can I fill my cell array?
    11 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Mira le
 el 26 de Nov. de 2019
  
    
    
    
    
    Editada: Philippe Lebel
      
 el 26 de Nov. de 2019
            Hello, 
U is cell:
U =
  1×2 cell array
    [1×2 double]    [1×2 double]
>> U{1}
ans =
     1     2
>> U{2}
ans =
     2     3
T= []
T has the union of element of U 1 2 3
S = {}; is empty in the first time 
I want to test each value of T if exist in U and the coy U{ i } in S, my S will be: 
S={ { 1 2 }, {{1 2} {2 3}}, {2 3} }
1 comentario
Respuesta aceptada
  Philippe Lebel
      
 el 26 de Nov. de 2019
        
      Editada: Philippe Lebel
      
 el 26 de Nov. de 2019
  
      here is my try:
U{1} =  [1,2];
U{2} = [2,3];
T = [1,2,3];
S = {};
for i = 1:length(T)
    temp_cell = {};
    k=1;
    for j = 1:length(U)
        if ismember(T(i),U{j})
            temp_cell{k} = U{j};
            k=k+1;
        end
    end
    S{i} = temp_cell;
end
The only difference with what you explained in your question is that the elements in U are lists, not cells. (ismember() does not work on cells)
0 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


