MATLAB Answers

checkbox object IF statement does not recognize the variables in MATLAB GUIDE

3 views (last 30 days)
Batuhan Yetisener
Batuhan Yetisener on 9 Dec 2017
Hello, everyone. Probably, I am making a utterly silly mistake here but here is the problem:
I have made a GUI using MATLAB GUIDE. I added some checkboxes to the GUI so that they will plot something on axes2 if checked and delete it otherwise. In case if you ask, there are going to be other plots so there is hold on and off. It works like this:
function checkbox1_Callback(hObject, eventdata, handles)
% Hint: get(hObject,'Value') returns toggle state of checkbox1
if get(hObject, 'Value') == 1
x = handles.x;
distanceX_Plot = evalin('base', 'CAN2_MPC_C19_Dist_X_VehObj0_Cval_MPC');
hold on;
distanceX_Plotted = plot(x,distanceX_Plot, 'r');
legend('Distance X')
hold off;
but the distanceX_Plotted in the IF part gets underlined and says variable might be unused and the second distanceX_Plotted in the ELSE statement says that variable may be used before it is defined.
The complete error is like this:
Undefined function or variable 'distanceX_Plotted'.
Error in untitled>checkbox1_Callback (line 224) delete(distanceX_Plotted);
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in untitled (line 42) gui_mainfcn(gui_State, varargin{:});
Error in>@(hObject,eventdata)untitled('checkbox1_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating UIControl Callback
Thanks for any help.


Sign in to comment.

Answers (0)

Sign in to answer this question.