Pushbutton in GUIDE gives the error "Undefined function or variable 'Test_wone_file_1'" only if other callback are previously activated
Afficher commentaires plus anciens
Here I am again in my series of questions to get from A to Z on my project. Here is my previous questions. I finally understood how to pass the handles between different callbacks. I want now to plot the curves of the selected checkboxes when I press the pushbutton "Plot!".
If If I press it as first thing nothing happens (the callback is still empty, see code below).
If I press it when I actually want to plot, I get the error: (notice that Test-wone-file_1 is my Guide).
Undefined function or variable 'Test_wone_file_1'.
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Test_wone_file_1('PB2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Do you have any Idea of what could it be? I attach as always the files and the file .TRA if someone wants to try the code.

% --- Executes on button press in PB1.
function PB1_Callback(hObject, eventdata, handles)
dname = uigetdir('C:\Users\MDl\Dropbox\epfl\Internship\matlab scripts');
if dname == 0
return
else
cd(dname)
end
F = dir('*.TRA');
for i = 1:length(F)
names{i,1} = F(i,1).name;
end
% Create cell 'false' of same length of names
checkboxes = num2cell(false(length(names),1));
% Create the two columns for uitable
myData =[checkboxes names];
% Set the uitable
columneditable = [true false];
columnformat = {'logical', 'char'};
set(handles.uitable2,'data', myData,...
'ColumnFormat', columnformat,...
'ColumnEditable', columneditable,...
'CellEditCallback',@fctCB);
handles.myData = myData;
handles.files = cell(length(F),2);
guidata(hObject, handles)
end
function fctCB(hObject,eventdata)
handles = guidata(hObject);
files = handles.files;
myData = handles.myData;
if eventdata.NewData == 1
% read the file only if it isn't already there
if isempty(files{eventdata.Indices(1),1})
fName = myData(eventdata.Indices(1),2);
fileName = fopen(fName{1,1}, 'r');
C = textscan(fileName, '%s %s %s', 'Delimiter', ';');
% create two subcells in files at the index eventdata containing the force and displacement
for i = 1:length(C{1,1})-17
files{eventdata.Indices(1),1}{i,1} = str2double(C{1,1}{i+17});
files{eventdata.Indices(1),2}{i,1} = str2double(C{1,2}{i+17});
end
end
else
end
% f1 = cell2mat(files{eventdata.Indices(1),1});
% f2 = cell2mat(files{eventdata.Indices(1),2});
% hold all
% plot(f1,f2)
handles.files(eventdata.Indices(1),:) = files(eventdata.Indices(1),:);
guidata(hObject, handles);
end
% --- Executes on button press in PB2.
function PB2_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
% files = handles.files;
% CB_answer = cell2mat(handles.uitable2.Data(1:end,1));
% cla;
% set(handles.axes1, 'Visible', 'off')
% for i = 1:length(CB_answer)
% if CB_answer(i) == 1
% f1 = cell2mat(files{i,1});
% f2 = cell2mat(files{i,2});
% hold all
% plot(f1,f2)
% else
% end
% end
% set(handles.axes1, 'Visible', 'on')
guidata(hObject, handles);
end
6 commentaires
OCDER
le 31 Oct 2017
I can't get the the error you're describing. In fact, it's working when you get rid of the "%" of the commented codes in PB2_Callback function.
When I click the checkbox, and then push Plot!, it plots just those that are selected. Is this an unwanted behavior? Also, you should edit the opening function to have handles.files = {}; initialization to prevent error if pressing the Plot! without selecting a directory.
% --- Executes just before Test_wone_file_1 is made visible.
function Test_wone_file_1_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for Test_wone_file_1
handles.output = hObject;
handles.files = {}; %<============HERE!!!!
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Test_wone_file_1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
end
Michael Daldini
le 1 Nov 2017
Michael Daldini
le 1 Nov 2017
Michael Daldini
le 1 Nov 2017
Modifié(e) : Michael Daldini
le 1 Nov 2017
OCDER
le 1 Nov 2017
How are you running the GUI? Do NOT double-click the .fig file, as this causes an error - it will skip the initialization functions, causing a lot of issues. Run the gui by doing this:
>> Test_wone_file_1
Michael Daldini
le 2 Nov 2017
Modifié(e) : Michael Daldini
le 2 Nov 2017
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Entering Commands dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!