Autoscale axis by a factor of 1000 around the minimum and maximum values of two data sets: Problem with all positive or all negative min/max values
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I have spent a few hours thinking about how to do this, and can't find a method that works.
Let's say I have 2 vectors that I want to fit, and then plot the fitline. Matlab stops graphing the fitline at the axis limits, so if one wants the fit to continue beyond the axis limits, he has to set those axis limits himself before plotting the fit.
I am using this command to autoscale back to an optimal view of the data points after the fits are plotted:
axis([LPData.xlimits(1,1) LPData.xlimits(1,2) LPData.ylimits(1,1) LPData.ylimits(1,2)])
Where LPData is just the structure used to exchange data between the several functions I use overall. Not relevant.
The limits are created using these commands. They are meant to leave a 5% overhang on all sides of the data points.
LPData.xlimits=([min(min(LPData.matx)),max(max(LPData.matx))] + [-1,1]*.05*range(LPData.matx,'all'));
LPData.ylimits=([min(min(LPData.maty)),max(max(LPData.maty))] + [-1,1]*.05*range(LPData.maty,'all'));
So, now to the actual problem:
Say I have a minimum of 0.42 and a maximum of 4.2, in both x and y for simplicity
I would then want the axis before the fits are plotted to be set to [-42 420 -42 420].
I don't know how to get matlab to go by a factor (like 1000) into away from the data set in both directions.
axis([LPData.xlimits(1,1)*1000 LPData.xlimits(1,2)*1000 LPData.ylimits(1,1)*1000 LPData.ylimits(1,2)*1000])
This would work if the lower limits of both sets are negative and the upper limits are positive. But it doesnt work if they are both either positive or negative, as the lower limit will be behind the highest plotted value if all values are positive (say we have a lower limit of 4.2, 4.2*1000=4200, so the data point at 4,2 isn't plotted) or negative (same thing other way around).
I can't find a method that covers all cases, and frankly don't really know to proceed. I think it is possible, I just don't know how.
Thank you & stay healthy
Claudius Appel
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Descriptive Statistics and Visualization에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!