範囲を指定してヒストグラムからaverage, variance, skewnessの算出

5 visualizaciones (últimos 30 días)
Naoki Ishibashi
Naoki Ishibashi el 20 de Sept. de 2016
Comentada: Naoki Ishibashi el 20 de Sept. de 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以下を切ってそれぞれの値を出せればと考えております。

Respuesta aceptada

michio
michio el 20 de Sept. de 2016
まずは論理配列の使用をお勧めします。例えば変数 x から x>0 という条件を満たす要素だけを取り出して x_new という新しい変数を作る場合、
x_new = x(x>0);
とのコマンドになります。x > 0 という条件式を x のインデックスとして使用できます。複数の条件を指定する事も可です。詳細は 条件を満たす配列要素の検索も参照ください。
簡単な例:
x = [1,2,3,4,5,6];
x(x<4)
また、記載のコードですと31個目のファイルのデータのみの mean/var/skewnessを計算する形となっていますが、すべてのデータの統計量を意図されていますか?
  1 comentario
Naoki Ishibashi
Naoki Ishibashi el 20 de Sept. de 2016
ご解答頂きありがとうございます。うまくできました。

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by