現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
ylim return type change
4 ビュー (過去 30 日間)
古いコメントを表示
Ian Nichols
2019 年 9 月 12 日
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 件のコメント
Nicolas B.
2019 年 9 月 12 日
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
2019 年 9 月 12 日
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
2019 年 9 月 12 日
編集済み: Adam Danz
2019 年 9 月 12 日
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
2019 年 9 月 12 日
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
2019 年 9 月 12 日
編集済み: Adam Danz
2019 年 9 月 12 日
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
2019 年 9 月 12 日
>> which varargout -all
C:\Program Files\MATLAB\R2018a\toolbox\matlab\lang\varargout.m
Ian Nichols
2020 年 2 月 6 日
I'm not sure how, AD?. SL confirmed that ylim.m cotains the expected code, and should therefore be working as expected.
Adam Danz
2020 年 2 月 6 日
編集済み: Adam Danz
2020 年 2 月 6 日
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
2020 年 2 月 6 日
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
2020 年 2 月 7 日
編集済み: Adam Danz
2020 年 2 月 7 日
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
2020 年 2 月 7 日
編集済み: Adam Danz
2020 年 2 月 7 日
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.
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
2020 年 2 月 7 日
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
2020 年 2 月 7 日
編集済み: Adam Danz
2020 年 2 月 7 日
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
2020 年 2 月 7 日
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
2020 年 2 月 7 日
編集済み: Adam Danz
2020 年 2 月 7 日
@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
2020 年 2 月 7 日
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.
回答 (1 件)
Ram Vijayaragavan
2020 年 2 月 6 日
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 件のコメント
Ian Nichols
2020 年 2 月 6 日
編集済み: Ian Nichols
2020 年 2 月 6 日
Thank you for your suggestions. EIther may work (not tested), but ylim should work, and doesn't; I shouldn't need a work around!
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- 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)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)