# Plot frequency along the y-axis without using a histogram

1 次查看（过去 30 天）
P_L 2019-3-22

Hi there, I am trying to generate a plot like this (please see image attached) and I have an example of my data/ code below. Please bare in mind I will have a lot more data then provided.
I am wanting to plot the frequency on the y-axis and the time along the x-axis but I do not know of a function that does this. I know you can create histograms but that is not the type of plot I want.
Any advice would be much appreciated!!
DateString = {'2012/07/07'; '2012/12/14'; '2013/04/23'};
formatIn = 'yyyy/mm/dd';
dates= datenum(DateString,formatIn);

### 采纳的回答

Rik 2019-3-22
Please don't delete a question because you're not getting the feedback you want.
Since you didn't provide any example data, I'll make some:
%work backwards from the result to create data
end_result=[140 60 30 20 18 18 15];
fun=@(count,pos) repmat(pos,1,count);
days_since_main_event=cell2mat(cellfun(fun,...
num2cell(end_result),num2cell(1:numel(end_result)),...
'UniformOutput',false));
%find the histogram
maxdays=max(days_since_main_event);
counts=histcounts(days_since_main_event,maxdays);
%do an 4th order polynomial fit - replace with actual expected function
p=polyfit(1:maxdays,counts,4);
xfit=linspace(1,maxdays,200);
yfit=polyval(p,xfit);
%plot data and fit in a clean figure
figure(1),clf(1)
plot(1:maxdays,counts,'rd')
hold on
plot(xfit,yfit,'k')

### 类别

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