フィルターのクリア

rows and columns in array

1 回表示 (過去 30 日間)
Rachel Ramirez
Rachel Ramirez 2020 年 12 月 3 日
回答済み: Swetha Polemoni 2020 年 12 月 7 日
Say I have an array with x amount of rows and 3 columns.
I want to count how many times does a specifc value repeat on the first column. So for example I want to know how many times do numbers 5,6,7,8,9 repeat in the first column. If they repeat less than 4 times then I want to delete the entire row where that value is in the first and/or second column to be deleted.
example: 5 has less than 4 combinations then the following rows would be deleted from the array.
5 1 100
2 5 800
5 5 500
  1 件のコメント
Image Analyst
Image Analyst 2020 年 12 月 3 日
Well fine, but you didn't show us the original matrix with the repeats and the "rows to be removed" in that matrix. What does your original matrix look like? and do you want 5,6,7,8,9 in order and that whole stretch of 5 adjacent numbers is repeated more or less than 4 times? Or do you want to delete rows where 5 is less than 4 times, and 6 is less than 4 times, etc.? The meantime, see ismember(), sum(), etc. And does repeated mean adjacent repeats, like [1,4,4,4,4,5,6] or can the repeat be separated, like [1,4,3,4,6,4,7,4]?

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

採用された回答

Swetha Polemoni
Swetha Polemoni 2020 年 12 月 7 日
Hi Rachel Ramirez,
It is my understanding that you want
  • To check how many times a number repeats in a particular row or column.
  • Delete that row or coumn if the count is less than 4.
A=randi(5, 10 ,10); % generating a random matrix with dimension 10X10
j=1;
for i= 1:10
count=sum(A(j,:)==5); % counting number of times 5 is repeting in jth row
if(count<4)
A(j,:)=[]; % deleting jth row if count is less than 4
j=j-1;
end
j=j+1;
end
Hope this helps.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by