How do you replace the entry of a matrix with a string?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ahmed
el 28 de Nov. de 2013
Comentada: oshawcole
el 6 de Dic. de 2017
I'm a little stuck
2 comentarios
Respuesta aceptada
Wayne King
el 28 de Nov. de 2013
Editada: Wayne King
el 28 de Nov. de 2013
You can't technically replace an entry of a matrix with an entire string. You would require a cell array for that. You can convert a matrix into numbers and replace single elements with single characters.
For example:
X = randi([0 6],20,20);
X = num2str(X);
X(X=='0') = 'M';
If you tried to replace with 'Monday', you'd get an assignment mismatch problem because you can't put 6 characters in a placeholder for one character.
You would have to use cell arrays for something like that.
0 comentarios
Más respuestas (2)
Jos (10584)
el 28 de Nov. de 2013
I suggest to use a cell array and keep the original numerical matrix for finding the elements that have to change:
X1 = randi([0 6],10,10)
X2 = num2cell(X1)
X2(X1 == 1) = {'Tuesday'}
1 comentario
Ver también
Categorías
Más información sobre Creating and Concatenating 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!