How to replace all the ones in a matrix with the string 'hey'?
Show older comments
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
Accepted Answer
More Answers (1)
John D'Errico
on 4 Dec 2017
0 votes
You can't. A matrix is composed of numbers. You cannot insert a string for some elements, replacing an arbitrary numeric element.
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!