How to plot a stacked histogram from multi text files

1 Ansicht (letzte 30 Tage)
Naoki Ishibashi
Naoki Ishibashi am 12 Sep. 2016
Bearbeitet: michio am 12 Sep. 2016
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!

Antworten (1)

michio
michio am 12 Sep. 2016
Bearbeitet: michio am 12 Sep. 2016
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 Kommentar
michio
michio am 12 Sep. 2016
Bearbeitet: michio am 12 Sep. 2016
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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by