How can i delete max values for each 5 rows in vector
古いコメントを表示
i have this vector A= 1 14 4 23 3 8 9 12 4 5 2 4 19 20 22
A=A'
The result will be R= 1 14 4 3 8 9 4 5 2 4 19 20
採用された回答
その他の回答 (1 件)
Davide Masiello
2022 年 12 月 29 日
編集済み: Davide Masiello
2022 年 12 月 29 日
The following code will apply to any lenght of A and any length N of window from which to delete the maximum, provided that length(A)/N is an integer.
A = [1 14 4 23 3 8 9 12 4 5 2 4 19 20 22];
R = rmvMaxEveryN(A,5)
function out = rmvMaxEveryN(array,N)
[~,idx] = max(reshape(array,[N,length(array)/N]),[],1);
idx = idx+(0:N:length(array)-N);
array(idx) = [];
out = array;
end
3 件のコメント
abdullah al-dulaimi
2022 年 12 月 29 日
abdullah al-dulaimi
2022 年 12 月 29 日
Davide Masiello
2022 年 12 月 29 日
Sorry I realised later there was a mistake and adjusted my answer.
カテゴリ
ヘルプ センター および 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!