필터 지우기
필터 지우기

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

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

댓글을 달려면 로그인하십시오.

채택된 답변

Naoki Ishibashi
Naoki Ishibashi 2016년 9월 12일
ありがとうございます。 それでやってみたところまた別のところでエラーが出てしまったのですがアドバイスいただけたら幸いです。
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
Naoki Ishibashi
Naoki Ishibashi 2016년 9월 13일
I can make histogram. I really appreciate for you support.
michio
michio 2016년 9월 13일
I'm glad it helped :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

michio
michio 2016년 9월 11일
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
michio
michio 2016년 9월 11일
histcounts関数はR2014bで導入された関数です。それ以前のバージョンをご利用の場合には、hist/histcで代用可能です。

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by