範囲を指定して最頻値
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
例えばA=[1,1,1,1,5, 2,2,2,2,3, 4,4,1]といった13×1の変数があるとします。
これらを上から順に5行毎に分けその最頻値を取りたいです。今回の場合はB=[1, 2, 4]といった感じで、最後は割り切れないがそのまま出力したいと思っています。
mode関数がよいようなのですが、以下のようにプログラムして上手くいきません。ご教授いただけると幸いです。よろしくお願いいたします。
for i = 1:length(A):5
k=i+4;
l=mode(A(i:k,:),2);
end
0 commentaires
Réponse acceptée
Hernia Baby
le 7 Sep 2022
6 commentaires
Hernia Baby
le 7 Sep 2022
すみません、一部間違えていました…
以下のコードになります
clear,clc;
A = readmatrix('saihin.csv');
Y = length(A)/50;
Y = fix(Y);
Y = Y + 1;
X = zeros(Y,1);
m = 1;
for ii = 1:50:length(A)
k = ii + 49;
if k > length(A)
X(m,1)=mode(A(ii:length(A),1));
else
X(m,1)=mode(A(ii:k,1));
end
m = m + 1;
end
X'
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!