Effacer les filtres
Effacer les filtres

複数のテキストファイ​ルからヒストグマムを​作る方法を教えてくだ​さい

3 vues (au cours des 30 derniers jours)
Naoki Ishibashi
Naoki Ishibashi le 11 Sep 2016
Commenté : michio le 14 Sep 2016
1000以上のtest fileをmatlab上にimportするとこまではできたのですが、そのデータを一つのヒストグラムにまとめる方法がわかりません。"hold"を使うと並列にグラフが重なってしまい、縦に各データを積み重ねて一つのヒストグラムを作りたいのですが何かアドバイスいただければ嬉しいです
  1 commentaire
michio
michio le 14 Sep 2016
参考:それぞれのファイルからのヒストグラムを積み重ねるには一例として
https://jp.mathworks.com/matlabcentral/answers/302703-how-to-plot-a-stacked-histogram-from-multi-text-files
で紹介するbar関数を使う方法があります。

Connectez-vous pour commenter.

Réponse acceptée

Naoki Ishibashi
Naoki Ishibashi le 12 Sep 2016
ありがとうございます。 それでやってみたところまた別のところでエラーが出てしまったのですがアドバイスいただけたら幸いです。
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 = hist(filename);
[counts,edges] = histcounts(x);
center = (edges(1:end-1)+edges(2:end))/2;
bar(center,counts,1)
end
end
error:
Attempt to execute SCRIPT hist as a function:
/Users/naoki/Documents/MATLAB/Add-Ons/TS2004.07/hist.m
Error in untitled5 (line 15)
x = hist(filename);
  10 commentaires
Naoki Ishibashi
Naoki Ishibashi le 13 Sep 2016
I can make histogram. I really appreciate for you support.
michio
michio le 13 Sep 2016
I'm glad it helped :)

Connectez-vous pour commenter.

Plus de réponses (1)

michio
michio le 11 Sep 2016
1000以上のtext fileにあるデータを全てまとめて1つのヒストグラムを作成されたいとのこと、これはそれぞれのファイルからのデータを縦に異なる色で重ねたヒストグラムをイメージすればいいでしょうか?例:
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
bar(y,'stacked')
それとも単にすべてのファイルからのデータをまとめた単色のヒストグラムでしょうか。
後者の場合、一旦すべてのデータを1つの変数にまとめた後にヒストグラムを描くことをお勧めいたしますが、データが多く1つの変数にまとめるのが難しい場合は histcounts 関数を使う方法はいかがでしょうか。http://jp.mathworks.com/help/matlab/ref/histcounts.html
各ファイルからのデータに対して histcounts 関数で各ビンのカウント数だけを計算しておき、最後にまとめて bar 関数でヒストグラムを描きます。下記は1つのデータ x に対して実行した例ですが、すべてのデータからのcountsだけを足しあわせて bar関数を実行すれば、すべてのデータのヒストグラムとなります。
x = randn(10000,1);
[counts,edges] = histcounts(x);
center = (edges(1:end-1)+edges(2:end))/2;
bar(center,counts,1)
  1 commentaire
michio
michio le 11 Sep 2016
histcounts関数はR2014bで導入された関数です。それ以前のバージョンをご利用の場合には、hist/histcで代用可能です。

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB 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!

Translated by