GUI - Once working codes doesn't work now with 'Struct contents reference from a non-struct array object' error

% --- Executes on button press in pb_fontsize.
function pb_fontsize_Callback(hObject, eventdata, handles)
% hObject handle to pb_fontsize (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fontsize = get(handles.ed_memo, 'fontsize');
new_fontsize = fontsize + 1;
set(handles.ed_memo, 'fontsize', new_fontsize);
The GUI callbacks using handles such as above is not working. The error mesage is 'Struct contents reference from a non-struct arraay object'. This error, i couldn't understand in any aspect: I checked tags, handle structure, and array taype as well. Also, codes that once used to work doesn't work anymore. If it is not the problem of the code, could it be the problem of MATLAB version update I haven't done?(using 2016a now) Following is the entire code that includes the callback above.
function varargout = GUIDE_Testing(varargin)
% GUIDE_TESTING MATLAB code for GUIDE_Testing.fig
% GUIDE_TESTING, by itself, creates a new GUIDE_TESTING or raises the existing
% singleton*.
%
% H = GUIDE_TESTING returns the handle to a new GUIDE_TESTING or the handle to
% the existing singleton*.
%
% GUIDE_TESTING('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUIDE_TESTING.M with the given input arguments.
%
% GUIDE_TESTING('Property','Value',...) creates a new GUIDE_TESTING or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GUIDE_Testing_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUIDE_Testing_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help GUIDE_Testing
% Last Modified by GUIDE v2.5 15-Feb-2017 11:38:55
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUIDE_Testing_OpeningFcn, ...
'gui_OutputFcn', @GUIDE_Testing_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before GUIDE_Testing is made visible.
function GUIDE_Testing_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to GUIDE_Testing (see VARARGIN)
% Choose default command line output for GUIDE_Testing
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes GUIDE_Testing wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = GUIDE_Testing_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function ed_memo_Callback(hObject, eventdata, handles)
% hObject handle to ed_memo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of ed_memo as text
% str2double(get(hObject,'String')) returns contents of ed_memo as a double
% --- Executes during object creation, after setting all properties.
function ed_memo_CreateFcn(hObject, eventdata, handles)
% hObject handle to ed_memo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pb_fontsize.
function pb_fontsize_Callback(hObject, eventdata, handles)
% hObject handle to pb_fontsize (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fontsize = get(handles.ed_memo, 'fontsize');
new_fontsize = fontsize + 1;
set(handles.ed_memo, 'fontsize', new_fontsize);

댓글 수: 2

It sounds as if your .fig does not have an ed_memo object in it.
Please attach your .fig as well.
actually it does have an according object... checked string and tag structure, and still can't find what's the problem

댓글을 달려면 로그인하십시오.

 채택된 답변

The posted code works for me in R2016b, provided that I run the .m (you cannot run by double-clicking on the fig)

댓글 수: 2

Oh! running .m on the menu works! Never thought of that. Thanks!
However, why the .fig doesn't work by clicking on push buttons? How is it different from running .m and clicking things?
It has never been possible to run GUIDE .fig figures just by launching it by double-clicking on the .fig file. There is some essential initialization code that is done by the .m file . In particular, the handles structure is created by the .m .

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

질문:

2017년 2월 15일

댓글:

2017년 2월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by