How to create a histogram without using the matlab function
6 次查看(过去 30 天)
显示 更早的评论
How to create a histogram without using the matlab hist function.
Given scattered data x = randn(1,100); y = randn(1,100);
with coresponding phase p = randn(1,100), having phase phase = exp(1i*p);
would like to create uniform grid, add the phase for the data points that are inside each bin.
This is to create a na intensity plot or coherent sum of the scattered data.
7 个评论
Guillaume
2020-3-1
@Ole, can you give a formal mathematical definition of what it is you want to calculate for a bin, because as you can see we're a bit confused.
采纳的回答
Guillaume
2020-3-1
As Steven said, use discretize to find the bin indices and then one of the many aggregation functions in matlab. With 3 vector inputs, I'd use the older accumarray:
%demo data and bin definitions
x = randn(1, 100);
y = randn(1, 100);
p = randn(1, 100);
phase = exp(1i*p);
xedges = [-Inf, -3:3, +Inf]; %there will be one less bin that there are edges
yedges = [-Inf, -3:3, +Inf]; %see documentation of discretize
%histogram building
destrow = discretize(y, ybins);
destcol = discretize(x, xbins);
phasehistogram = accummaray([destrow, destcol], phase, [numel(ybins), numel(xbins)] - 1);
Or you could put the vectors in a table, and call groupsummary which would do the binning and summing for you:
%demo data and bin definitions
x = randn(1, 100);
y = randn(1, 100);
p = randn(1, 100);
phase = exp(1i*p);
xedges = [-Inf, -3:3, +Inf]; %there will be one less bin that there are edges
yedges = [-Inf, -3:3, +Inf]; %see documentation of discretize
%table construction and histogram:
phasetable = table(x, y, phase);
phasehistogram = groupsummary(phasetable, {'x', 'y'}, {xedges, yedges}, 'sum', 'phase');
更多回答(1 个)
Steven Lord
2020-2-28
Consider using discretize to bin the data then passing that grouping information into groupsummary or splitapply.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!