How to plot a stacked histogram from multi text files

조회 수: 1 (최근 30일)
Naoki Ishibashi
Naoki Ishibashi 2016년 9월 12일
편집: michio 2016년 9월 12일
I want to make a stacked histogram from multi text files, from TS2004.07.01.0000.txt to TS2004.07.31.2100.txt. But following program has a error:
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'];
[y, b] = hist(filename);
bar(b,y,'stacked');
end
end
error:
>> hist
Attempt to execute SCRIPT hist as a function:
/Users/naoki/Documents/MATLAB/Add-Ons/TS2004.07/hist.m
Error in hist (line 15)
[y, b] = hist(filename);
please give me any advice!

답변 (1개)

michio
michio 2016년 9월 12일
편집: michio 2016년 9월 12일
In the script above you call hist function
[y, b] = hist(filename);
which causes an error, whose message indicates that hist.m (/Users/naoki/Documents/MATLAB/Add-Ons/TS2004.07/hist.m) is a script not a function. It seems it's not hist.m that Mathworks provides.
Did you intend to call hist.m as a function? If so, could you double-check if hist.m is a function? Is this a function that you created?
  댓글 수: 1
michio
michio 2016년 9월 12일
편집: michio 2016년 9월 12일
Once the above issue is resolved, bar function with 'stacked' option is a right direction to go if you want to make a stacked histogram.
But still I believe it should be called outside of for-loop as I mentioned in the related entry (<http://jp.mathworks.com/matlabcentral/answers/302666->)
y should be a 31 x nbin array, where nbin is the number of bins, in your case.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by