UserData of GUI figure has different type depending on operating system and/or Matlab-version
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello all, I have created a Matlab GUI using GUIDE, which is supposed to work on Windows, Mac OS and Linux systems. However, I came across a strange issue (platform inconsistency), when loading the GUI's UserData with:
ud = get(handles.GUI, 'UserData');
In almost all cases, ud is a normal empty variable (like ud = []); when loading it for the first time, before I assigned any values to it. As far as I have seen, this is always the case on Linux and Mac OS systems (tested with Matlab 2014b and 2016b) and also on "older" Windows systems. However, this seems to be different just on very specific platforms/versions: When I load the GUI on Windows10 with Matlab 2015b (maybe also other versions of Windows/Matlab as well, but I could not check it for all), the GUI's UserData is not a normal variable but an empty class 'matlab.graphics.Graphics'.
This is a particular problem, because I want to add parameters to ud if it is empty and then update the GUI's UserData with the new parameters, like:
ud = get(handles.GUI, 'UserData');
if isempty(ud)
ud.xyz = 10;
set(handles.GUI, 'UserData', ud);
end
However, adding the field xyz is not possible if ud is a class, as in the case described above using Windows 10. Consequently, the code above would work fine on Mac, Linux and some Windows machines, but would lead to an error on some other Windows machines (e.g. Windows 10 and Matlab 2015b).
Is there any particular reason why the UserData has a different type on different operating systems and/or versions, or is this a bug? In any case, I think it is problematic if the same Matlab versions lead to different results on different platforms.
In order to solve this problem, does someone know whether it is ok to just delete the content of ud before assigning new fields to the variable by ud = []? This would lead to the fact that ud is not a class anymore but a normal variable and I can assign fields to it consistently across all platforms? My potential solution would simply be:
ud = get(handles.GUI, 'UserData');
if isempty(ud)
ud = [];
ud.xyz = 10;
set(handles.GUI, 'UserData', ud);
end
From my perspective, this is not a problem at all, but I am just not sure whether this is ok, or whether there is a good reason why ud should be this class and should not be changed to a normal variable? Can someone shed light on this?
Thank you, Matthias
댓글 수: 0
답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!