How i convert a phrase like;(_x_1, or %diff) into a valid matlab variable? That i need to create a function?
    1 visualización (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Rosendo   Ramos
 el 3 de Sept. de 2020
  
    
    
    
    
    Comentada: Rosendo   Ramos
 el 6 de Sept. de 2020
            How i convert a phrase  like;(_x_1,  or  %diff) into a valid matlab variable?That i need to create a function? Im lost
RRN
1 comentario
Respuesta aceptada
  Fangjun Jiang
      
      
 el 3 de Sept. de 2020
        
      Editada: Fangjun Jiang
      
      
 el 3 de Sept. de 2020
  
      If just want to create a valid MATLAB variable name,
genvarname('_x_1')
genvarname('%diff')
matlab.lang.makeValidName('%diff')
2 comentarios
  Steven Lord
    
      
 el 3 de Sept. de 2020
				But then to assign a value to it you'd need to do something we don't recommend.
Since the question is marked with release R2020a, if you can use a table array the variable names in a table don't need to be valid MATLAB identifiers.
>> t = table(42, -999, 'VariableNames', ["_x_1", "%diff"])
t =
  1×2 table
    _x_1    %diff
    ____    _____
     42     -999 
Retrieving those variables from the table requires a very slightly different approach than if the variable names were valid MATLAB identifiers.
>> y = t.('%diff') % The parentheses are required in this case
y =
  -999
Más respuestas (0)
Ver también
Categorías
				Más información sobre Data Type Conversion 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!