Questions on errors in GUIDE
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
EDITED Hi there can someone help me to decipher the problem with my program, I have been receiving these error messages when i input data into my uitable and clicking the push button to run my code 'compare'. My code is as follows and the error message is attached behind it.
>> function Sample2_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 Sample2 (see VARARGIN)
% Choose default command line output for Sample2
handles.output = hObject;
storedvals = zeros(1,4);
% Update handles structure
guidata(hObject, handles);
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)
storedvals = handles.storedvals;
x = 0;
tableData = get(handles.uitable1, 'data');
compare(storedvals(1),storedvals(3));
if flag == 1
x = 'P1 Complies with A, B and C';
end
if flag == 2
x = 'P1 Complies with C and B';
end
if flag == 3
x = 'P1 Complies with A and C';
end
if flag == 4
x = 'P1 Complies with A';
end
if flag == 5
x = 'P1 Complies with B and C';
end
if flag == 6
x = 'P1 Complies with C';
end
if flag == 7
x = 'P1 Complies with C';
end
if flag == 8
x = 'Complies with None';
end
if flag == 9
x = 'P2 Complies with A, B and C';
end
if flag == 10
x = 'P2 Complies with A and B';
end
if flag == 11
x = 'P2 Complies A and C';
end
if flag == 12
x = 'P2 Complies A';
end
if flag == 13
x = 'P2 Complies with B and C';
end
if flag == 14
x = 'P2 Complies with C';
end
if flag == 15
x = 'P2 Complies with C';
end
if flag == 16
x = 'Complies with None';
end
set(handles.uitable1, 'Data', x)
% --- Executes when entered data in editable cell(s) in uitable1.
function uitable1_CellEditCallback(hObject, eventdata, handles)
% hObject handle to uitable1 (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE)
% Indices: row and column indices of the cell(s) edited
% PreviousData: previous data for the cell(s) edited
% EditData: string(s) entered by the user
% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
data = get(hObject, 'data');
indices = eventdata.Indices;
r = indices(:,1);
c = indices(:,2);
linear_index = sub2ind(size(data),r,c);
storedvals(linear_index) = data(linear_index);
handles.storedvals = storedvals;
guidata(hObject, handles);
>> Sample2
Undefined operator '==' for input arguments of type 'cell'.
Error in compare (line 3)
if Proc==1
Error in Sample2>pushbutton1_Callback (line 112)
compare(storedvals(1),storedvals(3));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Sample2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Sample2('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
2 commentaires
Stephen23
le 14 Fév 2018
Modifié(e) : Stephen23
le 14 Fév 2018
The error message shows where the error occurs:
Error in compare (line 3)
if Proc==1
However you did not show is the relevant code: you did not provide compare, and Proc does not occur anywhere in the code that you showed us. If you want help with this then please provide the code where the error actually occurs.
It is also not clear what relevance your question title "Questions on global variables in GUI" has to the question, as the code you showed does not define any global variables.
Also note using multiple if statements is very verbose, and could be replaced by one simpler switch statement:
switch flag
case 1
x = 'P1 Complies with A, B and C';
case 2
x = 'P1 Complies with C and B';
case 3
x = 'P1 Complies with A and C';
...
end
Or even simpler by one cell array and some indexing:
C = {...
'P1 Complies with A, B and C',...
'P1 Complies with C and B',...
'P1 Complies with A and C',...
...
};
x = C{flag};
(although I note that flag is also not defined anywhere in the code that you have shown us).
Réponse acceptée
Stephen23
le 19 Fév 2018
handles.storedvals is a cell array of the data in the uitable, therefore you need cell array indexing to access its contents:
compare(storedvals{1},storedvals{3});
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Debugging and Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!