Matlab GUI set error

1 次查看(过去 30 天)
Vineet Guru
Vineet Guru 2013-6-5
Hi,
I keep getting this error and I don't know why. Or I know what is causing it but don't know how to resolve it. I need to load a .mat file which has a variable within called sMap. But if I load this file, the handles.box causes an error with the following remark.
Reference to non-existent field 'box'.
How can I load this mat file and still have access to the box.
= = =
The code is as follows:
% --- Executes just before UnsupervisedRecognitionEngine is made visible.
function UnsupervisedRecognitionEngine_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 UnsupervisedRecognitionEngine (see VARARGIN)
% Choose default command line output for UnsupervisedRecognitionEngine
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes UnsupervisedRecognitionEngine wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = UnsupervisedRecognitionEngine_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;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
B = xlsread('animals_data_newanimal.xlsx');
sDataStr_rec = som_data_struct(B);
sDataStr_rec=som_normalize_data(sDataStr_rec,'som_var_norm');
load('e:\matlab\ute01\animals.mat');
rec_bmu = som_bmus(sMap, sDataStr_rec);
n = strcat('The Best Matched Neuron is: ', num2str(rec_bmu));
set(handles.box,'string', n);
function box_Callback(hObject, eventdata, handles)
% hObject handle to box (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 box as text
% str2double(get(hObject,'String')) returns contents of box as a double
% --- Executes during object creation, after setting all properties.
function box_CreateFcn(hObject, eventdata, handles)
% hObject handle to box (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

采纳的回答

Image Analyst
Image Analyst 2013-6-5
This link will help you solve this problem: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/. Basically set a breakpoint at the line it gives you an error at, examine the handles structure, and see that box is not a member of handles. My guess are that the load() statement loads a handles that blows away your existing handles, or that you have a "clear" or something similar in there somewhere.
  1 个评论
Vineet Guru
Vineet Guru 2013-6-6
Hi Image Analyst,
Thanks for your answer. I actually found the answer on another blog query to which you responded suggesting how to pass variables between functions. This helped.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by