Plot frequency along the y-axis without using a histogram

3 views (last 30 days)
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!!
Screenshot 2019-03-22 at 09.38.18.png
DateString = {'2012/07/07'; '2012/12/14'; '2013/04/23'};
formatIn = 'yyyy/mm/dd';
dates= datenum(DateString,formatIn);

Accepted Answer

Rik
Rik on 22 Mar 2019
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')

More Answers (0)

Community Treasure Hunt

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

Start Hunting!