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

조회 수: 7 (최근 30일)
Andrew Stark
Andrew Stark 2020년 11월 28일
답변: Walter Roberson 2020년 11월 28일
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