Afficher commentaires plus anciens
a = [ 2 3 4 5 5 5 5 5 6;2 3 4 4 4 4 5 5 6 ].'
の行列で1列目の数字が5つ連続した場合(5が5回連続)、連続した行から3つ前までの2列目の数字を平均する方法はありますか?(2 3 4 の平均)
解決策お願いします。
1 commentaire
Keito Endo
le 7 Oct 2021
Réponses (1)
Hernia Baby
le 8 Oct 2021
Modifié(e) : Hernia Baby
le 8 Oct 2021
n個続いたものから、2列目のm行前~1行前の平均を格納しています
n=5;
m=3;
a = [ 2 3 4 5 5 5 5 5 6 7 8 8 8 8 8;2 3 4 4 4 4 5 5 6 7 8 7 7 8 8 ]';
x = cell2mat(arrayfun(@(t)1:t,diff(find([1 diff(a(:,1)') 1])),'un',0))';
idx = find(x==n) - (n - 1);
for ii = 1:length(idx)
idx2 = idx(ii);
A{ii} = mean(a(idx2-m:idx2-1,2));
end
A
Catégories
En savoir plus sur 演算子と基本的な演算 dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!