Struct contents reference from a non-struct array object

I get this error when I run a MATLAB script in the following lines
% error in line 66
global WormTrackerPrefs
set(findobj('Tag', 'MIN_WORM_AREA'), 'String', num2str(WormTrackerPrefs.MinWormArea)) % line 66
set(findobj('Tag', 'MAX_WORM_AREA'), 'String', num2str(WormTrackerPrefs.MaxWormArea))
set(findobj('Tag', 'MAX_DISTANCE'), 'String', num2str(WormTrackerPrefs.MaxDistance))
set(findobj('Tag', 'MAX_SIZE_CHANGE'), 'String', num2str(WormTrackerPrefs.SizeChangeThreshold))
set(findobj('Tag', 'MIN_TRACK_LENGTH'), 'String', num2str(WormTrackerPrefs.MinTrackLength))
% error in line 220
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
% error in line 42
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Any help would be much appreciated. Thanks

 Risposta accettata

Guillaume
Guillaume il 21 Nov 2018
Modificato: Guillaume il 21 Nov 2018
You're using a global variable. We don't recommend using global variables as it's impossible to easily track what bit of code is doing (or not doing) what to the global variable. Global variables should be avoided.
Case in point, your code expects WormTrackerPrefs to be a structure. Turns out it isn't. Either some function somewhere is not designed properly and has changed it to something that is not a structure, or some function somewhere forgot to initialise that variable to a structure. The problem with global variables is that it's impossible to know which function is responsible. It's all down to you I'm afraid. Check all the functions that touch that global variable and make sure they don't change it to something that is not a structure. Also check that the global has actually been initialised to a structure before it's being used as such.
Or don't use global variables and avoid all the headaches. Since you're using GUIDE, use the handles variable for passing data between the various function of your GUI.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by