Running an error when attempting to set gca YTick marks.

3 views (last 30 days)
I have the following code:
set(gca,'YTick',energy_pixel);
However, I'm running an error that says:
Error using matlab.graphics.axis.Axes/set
Value must be a vector of type single or double whose values increase
But my energy_pixel variable is of type double and is either remaining the same or increasing:
energy_pixel = [0, 0, 0, 0, 71, 188, 595, 996]
Is there anyway to allow these numbers to be added to YTick? I can't change the values and I was wondering if there was a way I can work around the error itself.

Accepted Answer

Star Strider
Star Strider on 9 Jul 2018
We need more information about the values you’re plotting.
Experiment with this:
yt = get(gca, 'YTick');
energy_pixel = compose('%d', [0, 0, 0, 0, 71, 188, 352, 595, 996]);
set(gca, 'YTick',yt, 'YTickLabel',energy_pixel);
The compose function requires R2016b or later.
  2 Comments
Brianna Florio
Brianna Florio on 9 Jul 2018
This worked enough for me to execute the program for now. I'll ask what my boss actually wants to plot considering this was his code. Thanks for the help :)

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!