How do you add up data in a for loop to plot in a histogram?

1 次查看(过去 30 天)
n=100;
[Zf_S, Zf_L] = cellfun(@(B) bounds(B, 'all'), Zf);
Zf_max = max(Zf_L);
Zf_min = min(Zf_S);
Zf_vals = linspace(Zf_min, Zf_max, n);
[Df_S, Df_L] = cellfun(@(B) bounds(B, 'all'), Df);
Df_max = max(Df_L);
Df_min = min(Df_S);
Df_vals = linspace(Df_min, Df_max, n);
for i=1:1
ZZ = Zf{i};
DD = Df{i};
Zfr = discretize(ZZ, Zf_vals);
Dfr = discretize(DD, Df_vals);
zm = accumarray([Dfr Zfr], 1, [n n]);
zmf{i}=zm;
end
surf(Zf_vals, Df_vals, zmf);
This yields the error
Error using surf (line 71)
Z must be a matrix, not a scalar or vector.
Error in Analyze (line 236)
surf(Zf_vals, Df_vals, zmf);
What is the best way to add up all the zms so that I can plot all of the data in one histogram plot?

采纳的回答

Walter Roberson
Walter Roberson 2020-11-28
sum_zm = sum(cat(3, zfm{:}),3);
surf(Zf_vals, Df_vals, sum_zm, 'edgecolor', 'none');
This is not the best way: the best way is just to keep a running total without recording it in a cell array.

更多回答(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