필터 지우기
필터 지우기

how to delete a row by selected randomly from a matrix?

조회 수: 2 (최근 30일)
Shahzad Ali
Shahzad Ali 2017년 12월 21일
댓글: Shahzad Ali 2017년 12월 21일
  • 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"

채택된 답변

Roger Stafford
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 CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by