You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
ylim return type change
4 views (last 30 days)
Show older comments
Ian Nichols
on 12 Sep 2019
Yesterday, Matlab started returning querries to ylim as type cell, containing a 2 element double vector, rather than the 2 element double vector itself. Any ideas why?
For example:
figure; plot( 1 : 5)
ylim
should return:
ans =
1 5
But, now it returns:
ans =
1×1 cell array
{1×2 double}
This happened during a session!
I have to use cell2mat, now:
>> cell2mat( ylim)
ans =
1 5
I'm using R2018a.
I haven't overloaded ylim:
>> which ylim
C:\Program Files\MATLAB\R2018a\toolbox\matlab\graph3d\ylim.m
and ylim.m is:
[SL: Removed the text of the ylim function included in MATLAB. It does appear to be the version included in release R2018a.]
What has happened?
19 Comments
Nicolas B.
on 12 Sep 2019
Hey,
can you run this code:
f = figure;
plot(1:5);
f.Children.YAxis
And write here the result. ylim is returning you the content of YAxis... so maybe you have a multiple-axes plot... I don't know
Ian Nichols
on 12 Sep 2019
Nicolas,
Just a single axis as far as I can see...
f = figure;
plot(1:5);
f.Children.YAxis
ans =
NumericRuler with properties:
Limits: [1 5]
Scale: 'linear'
Exponent: 0
TickValues: [1 1.5000 2 2.5000 3 3.5000 4 4.5000 5]
TickLabelFormat: '%g'
Show all properties
Children: [0×0 GraphicsPlaceholder]
Color: [0.1500 0.1500 0.1500]
Direction: 'normal'
Exponent: 0
ExponentMode: 'auto'
FontAngle: 'normal'
FontName: 'Helvetica'
FontSize: 10
FontSmoothing: 'on'
FontWeight: 'normal'
HandleVisibility: 'off'
Label: [1×1 Text]
Limits: [1 5]
LimitsMode: 'auto'
LineWidth: 0.5000
MinorTick: 'off'
MinorTickValues: [1×32 double]
MinorTickValuesMode: 'auto'
Parent: [1×1 Axes]
Scale: 'linear'
TickDirection: 'in'
TickDirectionMode: 'auto'
TickLabelFormat: '%g'
TickLabelInterpreter: 'tex'
TickLabelRotation: 0
TickLabelRotationMode: 'auto'
TickLabels: {9×1 cell}
TickLabelsMode: 'auto'
TickLength: [0.0100 0.0250]
TickValues: [1 1.5000 2 2.5000 3 3.5000 4 4.5000 5]
TickValuesMode: 'auto'
Visible: 'on'
Adam Danz
on 12 Sep 2019
Edited: Adam Danz
on 12 Sep 2019
Ylim() wouldn't return a cell array even if there were multiple axes.
Ian, Clear everything (or researt Matlab) and from a clean slate, run ylim(). It should produce an empty figure/axis and an output ans=[0,1].
If that doesn't work or if it does work and the problem later appears, run this line
which ylim -all
My bet is that there's either a variable or perhaps a local or nested (or anonymous) function somehwere in your code named 'ylim'.
Ian Nichols
on 12 Sep 2019
Thanks, Adam.
>> ylim
ans =
1×1 cell array
{1×2 double}
>> which ylim -all
C:\Program Files\MATLAB\R2018a\toolbox\matlab\graph3d\ylim.m
>>
As you can see, there's nothing surprising there.
Rulerfunctions (called by ylim, see my OP) is defined:
function out = rulerFunctions(func, numargsout, args)
and within the body of the function:
% Initialize output variables.
out = cell(0);
and results are loaded into the cell, e.g.:
out{1} = fh(ruler, args{:});
Adam Danz
on 12 Sep 2019
Edited: Adam Danz
on 12 Sep 2019
The output of rulerFunctions should be a cell array since that function is called with the varargout output within ylim(). However, the output of ylim() should be a double.
Ian Nichols
on 12 Sep 2019
>> which varargout -all
C:\Program Files\MATLAB\R2018a\toolbox\matlab\lang\varargout.m
Ian Nichols
on 6 Feb 2020
I'm not sure how, AD?. SL confirmed that ylim.m cotains the expected code, and should therefore be working as expected.
Adam Danz
on 6 Feb 2020
Edited: Adam Danz
on 6 Feb 2020
Opa... you're right. I misread "does" as doesn't.
- Are you still using r2018a?
- Have you tried running this code on a different Matlab release or a different machine?
- Just to be super clear, is it true that every time you completely restart matlab and run ylim() it always produces a cell output containing a 1x2 vector of accurate y-limit ranges, without exception. Is that correct?
- Can you show us what's in your startup.m file (if you have one)?
Adam Danz
on 6 Feb 2020
I'm working in r2018a now so we're dealing with the same set of code. Could you try the following and tell me what you get for each step below? I hope this will help to narrow down the search.
- Clear out everything: clear all; close all; clc
- Open rulerFunctions.m: open('matlab.graphics.internal.ruler.rulerFunctions')
- Scroll down to line 119 which should be "return" and place a break on that line.
- From the command window, create an axes and call ylim with an output. axes(); y= ylim;
- Execution should have stop on line 119 in rulerFunctions. What is the value of the variable out just above that line? For me it is a 1x1 cell array containing a 1x2 double vector.
- Press F10 twice to get to the last line of ylim.m (end); What is the value of varargout? For me it is the same, a 1x1 cell array containingn a 1x2 double vector. The double vector should be passed as the output.
If there was something wrong with varargout such that it wasn't unpacking the cell arrays properly, I'd expect that you'd be seeing lots of other errors since varargout is so widely used.
Ian Nichols
on 7 Feb 2020
Edited: Adam Danz
on 7 Feb 2020
I don't think I have a startup.m:
>> which startup
'startup' not found.
rulerFunctions.m, line 119 is "end", the "return" is on line 120.
But looking at this may have revealed the problem...
Lines 104 to 121 are:
if nargs == 0
% .....
% .....
if .....
% ....
try
...
catch err
...
end
els
eif isscalar(...)
out{1} = ...;
else
.....
end
return
end
Spot the line break in the middle of the "elseif"!
The file modification date is 11/9/19, the day the problem occured!
For some reason rulerFunctions.m must have opened in my editor (debug on error / warn), and I must have hit <return> with the caret in the middle of the "elseif"... Wierd!
But fixing that line has fixed ylim!
Thank you!
Adam Danz
on 7 Feb 2020
Edited: Adam Danz
on 7 Feb 2020
That explains why the return was on line 120 for you instead of line 119 (in r2018a).
However, the major question now is how you were able to save that file after changing it. You sould have been blocked from saving the file after making changes.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/270426/image.png)
Did you open that file using open('matlab.graphics.internal.ruler.rulerFunctions') ?
Run this line of code below to determine if you have overshaddowed that function with a custom version of the same name.
which rulerFunctions -all
% It should result in 'rulerFunctions' not found.
Also, calling ylim() > rulerFunctions() should have thrown an error "Undefined function or variable 'els'." which would have prevented any output.
So, even though the problem may seem solved, something fishy happened in the background that is still worth investigating. Could you confirm that you are still able to open the rulerFunctions (using my open command pointing to that exact file), edit it, and successfully save it?
Ian Nichols
on 7 Feb 2020
No problem saving "C:\Program Files\MATLAB\R2018a\toolbox\matlab\graphics\+matlab\+graphics\+internal\+ruler\rulerFunctions.m", then (it seems), nor today.
>> which rulerFunctions -all
'rulerFunctions' not found.
I don't think calling ylim() would have thrown an error, because the second "if" in the snippet above evaluates as false, so the code advanced to the intact "else", skipping the broken "elseif", so the unexpected reference to "els" was never reached.
Yes, I can open, edit, and save the file (full path at the top of this reply) opened using: "open('matlab.graphics.internal.ruler.rulerFunctions')".
Adam Danz
on 7 Feb 2020
Edited: Adam Danz
on 7 Feb 2020
I don't know what to think of this. You shouldn't be permitted to save changes to that file. Have you tried to (carefully) make changes to other built-in matlab files? I think you should report this to tech support [link]. If you are not prevented from making changes to these types of files it could wreak all sorts of havoc as you've already experienced.
If you do follow that recommendation, please follow-up here with the results because this has me puzzled. Also, provide a link to this thread if you reach out to them.
Steven Lord
on 7 Feb 2020
By default that directory should probably not allow users to save changes to it.
But if you're running MATLAB as an administrator? I just tried that with a file in an installation on my machine and was able to save a change to one of the files under matlabroot in my C:\Program Files directory.
With great power comes great responsibility ... not to change files accidentally :)
Adam Danz
on 7 Feb 2020
Edited: Adam Danz
on 7 Feb 2020
@Steven Lord, I was hoping you'd chime in. I didn't know running Matlab as an admin would allow for changes to those functions. wow... this seems like such a bad idea. In the rare cases that changes must be made to root functions, the better option would be to overshaddow them with a custom version of the function with the same name. I can't imaging a benefit to the admin privileges of editing a root function.
Walter Roberson
on 7 Feb 2020
MATLAB is not itself restricting access to the installed files. MATLAB relies upon operating system access rights checking. At some point Windows 7 added controls to prevent non-privileged users from writing under Program Files, but Windows disables that protection for processes running as Administrator, because running as Administrator is intended to mean that you have rights to change nearly everything.
Answers (1)
Ram Vijayaragavan
on 6 Feb 2020
Hi Ian,
If you dont want to use the cell2mat function,one possible workaround can be
ax = gca %Get the current axis
ax.YLim
I Hope this solves your issue.
3 Comments
Ian Nichols
on 6 Feb 2020
Edited: Ian Nichols
on 6 Feb 2020
Thank you for your suggestions. EIther may work (not tested), but ylim should work, and doesn't; I shouldn't need a work around!
See Also
Categories
Find more on Startup and Shutdown 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!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)