OnOffSwitchState enumeration compatibility issue

12 views (last 30 days)
I have some old code which runs in R2019a and all older versions of Matlab but doesn't run in R2020a. It boils down to the fact that this statement:
length(get(figure,'visible'))
returns a 2 in R2019a but returns a 1 in R2020a.
I know that if the code was written properly it wouldn't depend on the fact that the visible property returns a character string, so perhaps the code should be fixed. But I'm wondering if there is a shortcut to get the code working. Perhaps there is a way to tell R2020a that for compatibility reasons it should return a character string when asking for the state of these properties (that return 'on' or 'off) instead of an OnOffSwitchState enumeration. I didn't see this mentioned as a compatibility issue in the release notes despite the fact that I think it is. I read the documentation about the OnOffSwitchState enumeration, but I didn't really understand what it was saying. Thanks for any wisdom on this topic that you may be able to offer. ~Paul
  1 Comment
Bruno Luong
Bruno Luong on 26 Aug 2020
This is crazy.
TMW once claimed the backward compatibility is they priority. It seems no longer the case.
User who cares about compatibility must implement the check which slows futher things down.
Thumb down. ;-(

Sign in to comment.

Answers (3)

Sanchita Ghosh
Sanchita Ghosh on 26 Aug 2020
Hi Paul
I assume that you have already observed that the return value of get(figure, 'visible') is 'on' in R2019a and on of type "OnOffSwitchState enumeration" in R2020a MATLAB version. Hence, the length of first case is 2 (as there are two letters in the return value of get(figure, 'visible') ) and 1 as the return value for the second case is of "OnOffSwitchState enumeration" which is a logical class (either 0 or 1).
The compatibility issue in the release notes is not yet there in the MATLAB documentation. I brought this issue to the concerned authorities and they may be looking into it and might be added in the future releases.
Now coming to your second point about "OnOffSwitchState enumeration":
matlab.lang.OnOffSwitchState is an enumeration class that derives from the logical class. So, in simple words you get either "on" or "off" as the output of this class . Here, "on" means logical "true" or "1" value and "off" means logical "false" or "0" value.

Paul Mennen
Paul Mennen on 26 Aug 2020
Thanks Sanchita. I now understand the problem better.
If you have the value "v" of the visibility property i.e.
v = get(object,'visible')
then in older versions of Matlab there are several ways to create a logical variable that is true when the object is visible. Three of these ways are shown below:
strcmp(v,'on')
length(v)==2
v(2)=='n'
But in version R2020a only the first method works. The other two methods may have been used in an effort at efficiency (perhaps misguided?) but they no longer work in R2020a because v is no longer a string. In fact, one might expect the first method to fail also since you would think that strcmp would allow only string arguments, but it appears that a special case was added to strcmp to allow this comparison to return true. It would have been nice if all 3 of these forms worked in R2020a, but if not, at the very least TMW should have mentioned that code such as this would no longer run and that such code would have to be modified. In the past, TMW seemed reluctant to make changes that broke old code and in the rare times that they did they were quite explicit in the release notes about why they did this and how to fix the old code. Sad that they now make such changes without even telling us about the possibility that it will break old code.

paul hiscock
paul hiscock on 23 Oct 2020
Whilst strcmp(v,'on') may work, strmatch(v,'on') does not as it used to.
It seems that strcmp(v,'on') can be used for cell arrays (at least in 2016b and 2020b), but it is not quite a simple replacement for strmatch.
Now need to check all my graphics routines to fix this. Not ideal, when I have a team of engineers using my libraries, and trying to find excuses to use Python instead!

Categories

Find more on Language Support in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!