Using strrep for matrix

3 次查看(过去 30 天)
xRobot
xRobot 2019-11-19
评论: xRobot 2019-11-20
Hello, I have some code that creates a scrambled character block of type char for instance
aaho
aoaa
daa
If i create a variable guess = 'hood'
how could i remove the word hood from the block and then display the block again with the removed 'hood'.
I have tried converting the block to a string array using "string()" then using "strrep() " to remove the the sequence and then convert it back to char but it did not work.
Any suggestions are greatly appeciated. Thanks in advance!

回答(1 个)

Guillaume
Guillaume 2019-11-19
Keeping your 2d character array as is:
yourarray(ismember(yourarray, 'hood', 'rows'), :) = [];
or
yourarray(all(yourarray == 'hood', 2), :) = [];
  1 个评论
xRobot
xRobot 2019-11-20
Instead of using ‘hood’ could I put a variable in there? Say guess = hood. Could I put guess in your code and it would work the same?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulation and Analysis 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by