Add a New Comment (Rich Markup)
( Jump to the original submission )
I would propose to close this report with "Won't Fix". I don't see a compelling use case for supporting this undocumented behavior.
i just meant consistent in behavior when a size = [0,0] 'something' is passed to it. struct() returns something of size = [1,1]. a lot of matlab functions seem to have nonstandard handling of (only ) [], while empties of any other size do other things. so, consistently inconsistent?
Definitely inconsistent. The input is supposed to be a scalar struct, not a struct array. It's nonsensical to have an optimget settings array with more than one element because then how would the interpreter decide which to apply?
note there is a difference between:
>> a = struct a = struct with no fields. >> a = struct.empty a = 0×0 empty struct array with no fields. >> optimget (struct,"Display") Unrecognized field name "Display". Error in optimget (line 94) o = options.(Names(j)); >> optimget (struct.empty,"Display") ans = []
so, it's somewhat consistent. when passed an empty array as an input OPTION structure, the returned value is always []. (unless you use the three input form in which case the return is always the default value set)
I think we should choose the path that makes sense here, rather than slavish Matlab compatibility. Testing with R2023a
optimget ([], 'Display') ans = [] optimget ([], 'Display', 'abc') ans = 'abc' optimget (struct, 'Display', 'abc') => Unrecognized field name "Display"
Seems inconsistent to accept empty matrix inputs and return the default value, but not accept empty struct inputs and return the default value. Also, what is the use case for this? More code---to handle weird exceptions---means more maintenance burden. Octave seems better to me because it checks the first argument for being the expected type (struct) and for the third example, it returns "abc" because Octave correctly finds that there is no field "Display" in the empty struct. If anything, I think the input validation could be made more precise. The code in optimget.m is
if (nargin < 2 || ! isstruct (options) || ! ischar (optname)) print_usage (); endif
I would use print_usage () only for the case where the number of arguments is wrong. I would then break out the argument 1 and argument 2 checking to produce specific error messages about what is wrong with each input.
R2023a i get the same `help optimget` output including [] comment.
Funny. I looked directly at my ML R2019b help, which one would think is the same as https://www.mathworks.com/help/releases/R2019b/matlab/ref/optimget.html?s_tid=doc_ta But it is not. Here is what I get:
>> help optimget
optimget Get OPTIM OPTIONS parameters. VAL = optimget(OPTIONS,'NAME') extracts the value of the named parameter from optimization options structure OPTIONS, returning an empty matrix if the parameter value is not specified in OPTIONS. It is sufficient to type only the leading characters that uniquely identify the parameter. Case is ignored for parameter names. [] is a valid OPTIONS argument. VAL = optimget(OPTIONS,'NAME',DEFAULT) extracts the named parameter as above, but returns DEFAULT if the named parameter is not specified (is []) in OPTIONS. For example val = optimget(opts,'TolX',1e-4); returns val = 1e-4 if the TolX parameter is not specified in opts. See also optimset.
>> ver
----------------------------------------------------------------------------------------------------- MATLAB Version: 9.7.0.1737446 (R2019b) Update 9
I do not see that text in the current online Matlab documentation here: https://www.mathworks.com/help/matlab/ref/optimget.html Are you looking at the documentation for some older version?
The doc has ---------- ... [] is a valid OPTIONS argument. VAL = optimget(OPTIONS,'NAME',DEFAULT) extracts the named parameter as above, but returns DEFAULT if the named parameter is not specified (is []) in OPTIONS. For example val = optimget(opts,'TolX',1e-4); returns val = 1e-4 if the TolX parameter is not specified in opts. ---------- which sounds pretty clear to me. That is, optimget([],'TolX',1e-4) should return 1e-4.
ML doc specifies that the first argument should be a struct, and that the return argument should also be a struct. So this looks like a doubly undefined behavior (or undocumented "feature" if you prefer).
In Matlab, optimget ([], "Display", "notify") returns 'notify' whereas ocatve returns an error.
(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)
Attach Files: Comment:
No files currently attached
Depends on the following items: None found
Items that depend on this one: None found
There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.
Only project members can vote.
Please enter the title of George Orwell's famous dystopian book (it's a date):
Follow 3 latest changes.
Copyright © 2023 Free Software Foundation, Inc. Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved. The Levitating, Meditating, Flute-playing Gnu logo is a GNU GPL'ed image provided by the Nevrax Design Team. Source Code
Powered by Savane 3.12