Plotting pdf on top of histogram

39 次查看(过去 30 天)
Charith Ranatunga
Charith Ranatunga 2020-4-22
评论: Tommy 2020-4-22
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
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)

请先登录,再进行评论。

回答(0 个)

类别

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