Convert Array of Float to comma delimited string
    9 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Ted Baker
 el 16 de Nov. de 2020
  
    
    
    
    
    Comentada: RST
 el 3 de Ag. de 2023
            Hi I would like to convert an array of floats to a single string, with commas separating the numbers, as below:
data = [1 2 3 4];
output = "1, 2, 3, 4"
However, I cannot seem to get the commas implemented - here is my attempt:
data2 = cellstr(num2str(data));
output = strjoin(data2, ', ');
i then get an output of;
'1 2 3 4'
What am I doing wrong?
0 comentarios
Respuesta aceptada
  Stephen23
      
      
 el 16 de Nov. de 2020
        
      Editada: Stephen23
      
      
 el 16 de Nov. de 2020
  
      data = [1,2,3,4];
strjoin(compose("%d",data),", ") % provides formatting control
strjoin(""+data,", ") % default formatting
2 comentarios
  RST
 el 3 de Ag. de 2023
				And for 2D arrays we can do:
data = rand(3,4);
csvData = strjoin( join( compose('%.3f', data), ', '), newline())
Más respuestas (0)
Ver también
Categorías
				Más información sobre Cell Arrays 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!


