How to replace non zero value with character
2 次查看(过去 30 天)
显示 更早的评论
Matrix A = [0 0 1; 1 0 0;0 2 0];
I want to create another matrix replacing non zeros elements (i.e. (1,3), (2,1), (3,2) with character string, e.g. OK
Please suggest....
0 个评论
回答(1 个)
Stephen23
2017-6-23
>> A = [0 0 1; 1 0 0;0 2 0];
>> C = repmat({''},size(A));
>> C(A~=0) = {'OK'}
C =
'' '' 'OK'
'OK' '' ''
'' 'OK' ''
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!