How to replace all the ones in a matrix with the string 'hey'?
Mostrar comentarios más antiguos
matrix= [1 0 0.1 0.001 4; 5.9 2.1 3.15 8.95 1.11]
All the ones should be replaced with 'hey'
This is my code
matrix= [1 0 0.1 0.001 4; 5.9 2.1 3.15 8.95 1.11];
matrix= num2str(matrix);
matrix(matrix=='1') = 'h'
when I replace 'h' with 'hey' it gives me this error
matrix(matrix=='1') = 'hey'
I have just started to learn MATLAB. please help
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 4 de Dic. de 2017
0 votos
You can't. A matrix is composed of numbers. You cannot insert a string for some elements, replacing an arbitrary numeric element.
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!