範囲を指定してヒストグラムからaverage, variance, skewnessの算出
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Naoki Ishibashi
le 20 Sep 2016
Commenté : Naoki Ishibashi
le 20 Sep 2016
以下のプログラムで複数のテキストデータを読み込み、countsでヒストグラムを作り、average, variance, skewnessをそれぞれ算出するようにしたのですが、データにはエラーが含まれておりそのエラーだけ範囲指定をして除くなど、何か方法ありましたら教えていただけると幸いです。
nbins = 150;
total_counts = zeros(1,nbins);
for i = 1:31
if i<10
daystr = ['0', num2str(i)];
else
daystr = num2str(i);
end
for k = 0:7
j = 3*k;
if j<10
hour = ['0', num2str(j)];
else
hour = num2str(j);
end
filename = ['TS2004.07.',daystr,'.',hour,'00.txt'];
x = load(filename);
[counts,edges] = histcounts(x,nbins, 'Normalization', 'pdf');
total_counts = total_counts + counts;
end
end
center = (edges(1:end-1)+edges(2:end))/2;
bar(center,total_counts,1);
xlim([200 350]);
M = mean(x);
V = var(x);
S = skewness(x);
データのエラーは下の図のように-1000が明らかなエラーとなっていますので0以下を切ってそれぞれの値を出せればと考えております。
0 commentaires
Réponse acceptée
michio
le 20 Sep 2016
まずは論理配列の使用をお勧めします。例えば変数 x から x>0 という条件を満たす要素だけを取り出して x_new という新しい変数を作る場合、
x_new = x(x>0);
簡単な例:
x = [1,2,3,4,5,6];
x(x<4)
また、記載のコードですと31個目のファイルのデータのみの mean/var/skewnessを計算する形となっていますが、すべてのデータの統計量を意図されていますか?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!