How to plot a stacked histogram from multi text files

2 ビュー (過去 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 Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by