How to plot a stacked histogram from multi text files
1 次查看(过去 30 天)
显示 更早的评论
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
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
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 Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!