How to remove elements from a matrix?
显示 更早的评论
采纳的回答
更多回答(1 个)
nkeep = 4;
str = 'thestring';
str(randperm(numel(str),nkeep))
3 个评论
If you want to keep the same order, and have random number of characters removed, then you could do this:
>> str = 'thestring';
>> N = numel(str);
>> str(randperm(N,randperm(N,1))) = []
str = teting
or use randi instead:
>> str = 'thestring';
>> N = numel(str);
>> str(randperm(N,randi(N,1))) = []
str = ttrin
John Mat
2017-6-6
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!