Plot frequency along the y-axis without using a histogram
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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);
0 Kommentare
Akzeptierte Antwort
Rik
am 22 Mär. 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')
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Histograms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!