![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/286488/image.png)
Plotting pdf on top of histogram
조회 수: 73 (최근 30일)
이전 댓글 표시
Hi Im trying to plot a probability density function on top of a histogram I plotted for idle current and idle energy based off a LoRa transmission data. The csv data included time in the first column and current in the second and I found the energy using a given value of 12V. I tried plotting it but got an error, any advice would be great :) .
idle_data = importdata('idlecurrent.csv');
%Lora_t = Lora_0tx(:,1);
idle_time = idle_data(:,1);
idle_current = idle_data(:,2);
idle_timetot = (max(idle_time) - min(idle_time));
idle_energy = idle_current.*12*idle_timetot;
mean_current = mean(idle_current);
stdev_current = std(idle_current);
figure(4)
hist_current = histogram(idle_current);
hold on
current_pdf = histogram(idle_current,'Normalized','pdf');
hold off
figure(5)
hist_energy = histogram(idle_energy);
hold on
energy_pdf = histogram(idle_energy,'Normalized','pdf');
hold off
댓글 수: 1
Tommy
2020년 4월 22일
histogram does not accept 'Normalized' as an argument, but rather 'Normalization':
current_pdf = histogram(idle_current, 'Normalization', 'pdf');
Your code will plot two histograms on top of each other. That may be what you want, but depending on the amount of data the first histogram might tower above the second, making the second essentially invisible. In case you are instead wanting to plot the actual pdf on top of your (normalized) histogram, you can do it if you know the pdf:
A = normrnd(0,1,1000,1);
histogram(A, 'Normalization', 'pdf');
hold on;
ax = gca;
x = linspace(ax.XLim(1), ax.XLim(2), 1000);
plot(x, normpdf(x), 'LineWidth', 2)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/286488/image.png)
답변 (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!