How to change axis size without affecting bin size
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Andrew Stark
am 26 Nov. 2020
Kommentiert: Andrew Stark
am 28 Nov. 2020
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 ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/430233/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/430233/image.jpeg)
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?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 27 Nov. 2020
[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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Histograms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!