Plot frequency along the y-axis without using a histogram
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
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')
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!