how to delete a row by selected randomly from a matrix?
2 次查看(过去 30 天)
显示 更早的评论
- d=2;
- for i=1:10
- pop(i,:)=rand(1,d);end
- M=pop(randi(size(pop,1)),:)
- now i want to know that how to delete this M without knowing the row number and the values of the row, just to delete it by using The "M"
0 个评论
采纳的回答
Roger Stafford
2017-12-21
This depends on M being exactly equal in each of its elements to the corresponding elements of one of the rows of 'pop':
for k = 1:size(pop,1)
if all(M==pop(k,:)
pop(k,:) = []; % Delete the matching row of pop
break;
end
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!