フィルターのクリア

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
  1 件のコメント
Shahzad Ali
Shahzad Ali 2017 年 12 月 21 日
Thank you so much sir, it worked.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by