How to change axis size without affecting bin size

조회 수: 1 (최근 30일)
Andrew Stark
Andrew Stark 2020년 11월 26일
댓글: Andrew Stark 2020년 11월 28일
n=100;
for i=1:3000
ZZ=Zf{i};
DD=Df{i};
Zf2=linspace(min(ZZ(:)),max(ZZ(:)),n);
Df2=linspace(min(DD(:)),max(DD(:)),n);
Zfr=interp1(Zf2,1:numel(Zf2),ZZ,'nearest');
Dfr=interp1(Df2,1:numel(Df2),DD,'nearest');
zm=accumarray([Dfr Zfr],1,[n n]);
surf(zm);
hold on
end
This code generates the following histogram
How do I modify the x and y axis to make them go up until the max of Dfr and Zfr but still have the number of bins remain 100?

채택된 답변

Walter Roberson
Walter Roberson 2020년 11월 27일
[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);
Now do your interpolation with respect to Zf_vals and Df_vals instead of with respect to a vector that changes each time.
Hint: discretize() instead of interpolation .
  댓글 수: 9
Andrew Stark
Andrew Stark 2020년 11월 28일
My apologies for the banana plot the following code was used
for i=1:1
Zf2=Zf{i};
Df2=Df{i};
plot(Df2,Zf2)
hold on
end
Whereas for the histogram the code was
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]);
surf(Df_vals, Zf_vals, zm);
hold on
end
Andrew Stark
Andrew Stark 2020년 11월 28일
Additionally what is the best command to use in a for loop that will continuously add up the zm arrays

댓글을 달려면 로그인하십시오.

추가 답변 (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