Merge Variables in Table
    1 visualización (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Alexandra Kopaleyshvili
 el 12 de Jun. de 2021
  
    
    
    
    
    Editada: Alexandra Kopaleyshvili
 el 13 de Jun. de 2021
            I would like to create a for loop which can merge variables dynamically by first letter, excluding the number standing behind the letter.
from this:

to this:

Thanks!
0 comentarios
Respuesta aceptada
  Walter Roberson
      
      
 el 13 de Jun. de 2021
        names = YourTable.Properties.VariableNames;
initials = extractBefore(names, 2);
[G, id] = findgroups(initials);
newTable = table();
for K = 1 : length(id)
   newTable.(id{K}) = [YourTable{:,G==K}];
end
2 comentarios
  Alexandra Kopaleyshvili
 el 13 de Jun. de 2021
				
      Editada: Alexandra Kopaleyshvili
 el 13 de Jun. de 2021
  
			
		Más respuestas (0)
Ver también
Categorías
				Más información sobre Tables 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!