Predetermine axis limits without plotting

I have a very large number of data sets (blocks) that I am currently extracting the min and max values from and plotting the results with yline in order to determine and extract the y-axis limits and major tick values. These results are used externally from MATLAB later to generate a seperate set of plot figures with consist axis scaling. This process works great as the y-axis limits and major tick values produced in this fashion are ideal. However, the issue that I have is that when trying to perfrom this task on the order of 1e4+ times it becomes cumbersome due to the need to actually have to plot the extracted extents first. This process is sped up by creating a non-visible figure, but creating, plotting, and closing the figure for each data block is still the largest task time. I have also tried using basic methods such as rounding and/or padding the extracted extents, but do not like my current approach to this since it does not always produce "clean" values for the upper and lower tick marks.
Other than plotting, does MATLAB have a built-in function that can be used to determine what the axis properties would be for a given set of values?

Answers (1)

You can give it a try to add small value to the maximum value of the array. It can either be 10% or 20% of the extreme.
x_vals=rand(1,10)
y_vals=rand(1,10)
threshold_coeff= 0.2 % 20 % of the extreme
x_lower=min(x_vals) - threshold_coeff*(min(x_vals))
y_lower=min(y_vals) - threshold_coeff*(min(y_vals))
x_upper=max(x_vals) + threshold_coeff*(max(x_vals))
y_upper=max(y_vals) + threshold_coeff *(max(y_vals))
You can write above equation as:
x_lower=min(x_vals)*(1-threshold_coeff)
Hope this helps, or you can take a look into this thread.

1 Comment

Ankur,
Thank you for your reply to this post. However, your suggestion is no different than the round and padding methods that I currently employ. The problem with this method is that for min values near zero (e.g. 1e-5) and max values much greater (e.g. 1e16). The resulting limits do not produce "clean" values on the upper and lower tick marks. By "clean", I am trying to obtain upper and lower tick mark values that also coincide with the axis limits.
I should also note that I am sometimes working with data sets that are best viewed with a linear scale, and at other times with a logarithmic scale.

Sign in to comment.

Products

Release

R2020b

Asked:

on 1 Mar 2021

Commented:

on 1 Mar 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!