GUI not storing handles correctly

1 view (last 30 days)
Zeke Merchant
Zeke Merchant on 9 Nov 2014
Edited: per isakson on 9 Nov 2014
data is a folder containing about 12 excel files
I need the data in the entire column of each excel file labeled "HeadRight"
The data is to later be put into a matrix using a user defined function and then used to build a graph via the patchline function.
However, every time I run the code, it says that "HeadRight" is undefined code:
% --- Executes on button press in headdata.
function headdata_Callback(hObject, eventdata, handles)
% hObject handle to headdata (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of headdata
handles = guidata(hObject);
if (get(hObject,'Value') == get(hObject,'Max'))
for i = 1:length(handles.data)
handles.datapatch = handles.data(i).HeadRight
handles.int = handles.data(1).DetectionCode
guidata(hObject,handles)
display('headdata works')
end
end
end
  5 Comments
Jan
Jan on 9 Nov 2014
@Zeke Merchant: I do not understand, where HeadRight is created. It is not created in the posted code, so I guess you fogot a guidata update after it has been defined anywhere else.
Please care for posting a full copy of the error message. A rough rephrasing cinceals important details usually.
Zeke Merchant
Zeke Merchant on 9 Nov 2014
The max property of the pushbutton is checked because there are 3 options for data output: headdata, platedata, and relheaddata. I've tried using a buttongroup with 3 "cases" but this method didn't work so I'm trying another.
"data" was added to the handles structure in an earlier subfunction that can be seen below:
code:
function readdir_Callback(hObject, eventdata, handles)
% hObject handle to readdir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
directory=get(handles.textbox1,'String');
files=dir(directory);
for i=1:(length(files)-2)
s=files(i+2).name;
s=strcat('\',s);
L=strcat(directory, s);
[num, txt, all] = xlsread(L); %%your excel file must not have first line titles
for j=1:length(txt);
txt{j}=regexprep(txt{j},'','NaN');
%delete space in string
% text{j}=num(:,j);
handles.data(i).(txt{j})=num(:,j);
guidata(hObject,handles);
end
guidata(hObject,handles)
end
display('readdir works')
"HeadRight" and "RightFrontPlate" are the column names in each of the 12 excel files in "data."
My goal is to have "datapatch" be either the head right, right front plate, or relative head data (simply a difference of the first two) from each of the excel files, based on which radiobutton the user chooses.
The error message that prints can be seen below:
??? Reference to non-existent field 'HeadRight'.
Error in ==> GUI_Patchline>headdata_Callback at 309
handles.datapatch = handles.data(i).HeadRight
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> GUI_Patchline at 41 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)GUI_Patchline('headdata_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
Here's the kicker, when I click on the platedata radiobutton instead, here's what the updated handles list looks like:
handles =
figure1: 173.0012
platedata: 12.0013
relheaddata: 11.0013
headdata: 10.0013
patchradio: 9.0013
int_2_2: 8.0013
int_2_1: 7.0013
int_1_2: 6.0013
int_1_1: 5.0013
stimno: 4.0013
stimyes: 3.0013
plotpatchline: 2.0013
readdir: 1.0013
choosedir: 0.0013
textbox1: 174.0012
output: 173.0012
data: [1x12 struct]
int1_1: 0
int1_2: 2500
int2_1: 2501
int2_2: 5000
datapatch: [5500x1 double]
int: [18x1 double]
platedata works
The datafiles are about 5000-6000 cells long, int is an excel file that I made and has the right dimensions, and the int*_* terms are user defined. The platedata radiobutton works, but the headright one creates that error message.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 9 Nov 2014
Evidently your "data" field does not have a HeadRight field. What does this say:
fn = fieldnames(handles.data(1))
in the command window.
  1 Comment
Zeke Merchant
Zeke Merchant on 9 Nov 2014
The command window reads:
"??? Undefined variable "handles" or class "handles.data"."
but the bottom of the handles list says:
int1_1: 0
int1_2: 2500
int2_1: 2501
int2_2: 5000
data: [1x4 struct]
datapatch: [4000x1 double]
int: [18x1 double]

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!