Change axis values of an already existing figure

I have a figure that has axis already and numbers in them. I wish to change the axis values display values so that they read differently. I only have the .fig file and the numbers on the axis don't matter to much, so changing them is only for better readability (say put in in a positive scale from 0 to 10. How does one do that without screwing up the figure?

 Accepted Answer

ax = findobj(0, 'type', 'axes', '-or', 'type', 'matlab.graphics.axis.Axes');
if isempty(ax); error('No axes found'); end
if length(ax) > 1; error('Multiple axes found'); end
xticks(ax, [new list of x tick positions])
set(ax, 'XTickLabel', {'0' '1' '2' '3'});

7 Comments

note I don't have anything but the .fig file...how do I start using it in the first place?
fig = openfig('NameOfFile.fig');
ax = findobj(fig, 'type', 'axes', '-or', 'type', 'matlab.graphics.axis.Axes');
I am getting error:
Undefined function or variable
'xtick'.
any ideas?
Ok Im updating to 2018a and see if that fixes it...
Should have been xticks() instead of xtick()
In any case you can
set(ax, 'XTick', [new list of x tick positions], 'XTickLabel', {'0', '1', '2', ....})
hmmm I'm trying to change the other axis...its changing the wrong one.
I think it would be nice to note to future readers what ur code does with some comments.
xticks(ax, [new list of x tick positions])
is the "real" actual values on the axis and:
set(ax, 'XTickLabel', {'0' '1' '2' '3'});
is the new display "labels" that will appear on the figure. I made the `[new list of x tick positions]` be the same length as `{'0' '1' '2' '3'}`, one new display label for each true value on the axis.
thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Tags

Community Treasure Hunt

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

Start Hunting!