MATLAB does not have any built-in functionality for centering the coordinate axes around the origin. This tool is a first fix for solving this. An example script is included showing how to use the function.
Tested on MATLAB 2007b. Works fine, as long as the figure is not resized after the function is called.
thanks a lot for this!
Thanks! I have included your suggested fix, and it appears to be working in the latest release as well (2015b). Will upload the new version in a minute (ver. 1.2).
if the 'Units' property of the figure is fixed as "normalized" there is a problem in the arrow size.
Here is an apparent fix (after definition of figpos):
screensize = get( 0, 'ScreenSize' );
figpos = figpos.*screensize;
Glad you liked it! Never tried doing it for 3D, but in principle you should be able to hack the code to do it.
This is a great bit of code and just what I needed.
Is there a simple way to make this work in 3D?
I deliberately removed the end tick labels in on the axes, simply because I didn't think it looked so good. It appeared that changing this takes a bit of fixing of the code to make the arrowheads appear in the right place. Anyway, I'm on it, and I'll post a new version in a couple of days.
Thank u Johan, I downloaded "centeraxes", it solved my problem.
How do I get the axes ticked from -1 to 1 please? now it's ticked only from -0.9 to 0.9.
Thank you John!
The option of where to put the center is a simple fix, and I'll definitely deal with that. The other issue is more serious, and unfortunately slightly harder to solve. Nevertheless, I'll give it a go.
Another limitation at the moment is that the tick marks and arrowheads tend to scale if the image is resized after the call to centeraxes.
Anyway, thanks for the feedback.
Pretty decent. Doesn't work in cases where you have multiple axes, as you sometimes get with
But otherwise, it works pretty darned well. One suggested improvement: allow an option for what "center" to use, so that I could have x- and y-axes intersecting at (-1, 2), if I so chose.
Fixed bug related to axes in 'Normalized' 'Units'.
Changed the x axis and y axis tick labeling so that it now includes also the end points. As a consequence, the axes are now 10% longer in order to make room for the arrowheads.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.