GUI Has Error Although It Worked Fine Before and I Did Not Change Code

Hi, when I first created my GUI everything worked fine. Then I closed Matlab, reopened my GUI and ran it and now it won't run because it has errors in its internal function when it worked fine before. I did not change anything in my code so I don't understand why it's no longer working when I reopen Matlab. I attached my code below. This is the error message I receive:
Undefined function or variable 'writePWMDutyCycle'.
Error in code1>pushbutton1_Callback (line 98)
writePWMDutyCycle(a,'D10',0);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in code1 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)code1('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
This is my first time posting so please let me know if I need to clarify anything or change my formatting.

6 Kommentare

Somehow, the Arduino support package is no longer on your MATLAB path. You might need to reinstall the Arduino support package.
L
L am 1 Sep. 2017
Bearbeitet: L am 1 Sep. 2017
It is still on my add-on list and it is updated, but I re-installed it anyways and I still get the same error.
The only way I can make my GUI work is to redo/remake everything from scratch. Then if I keep running it (without changing the code at all), after a while I get the same error again.
I do not see anything suspicious in the code.
Before the problem occurs, what shows up for
which -all writePWMDutyCycle
and what shows up when the problem occurs?
Before the problem starts, save a copy of the result of path(), and then when the problem occurs, have another look at path() and compare.
Try adding the path to writeDWMDutyCycle inside the code1_OpeningFcn block.
function code1_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
addpath( folder ); % Here, Add the folder path to writeDWMDutyCycle
guidata(hObject, handles);
L
L am 1 Sep. 2017
Bearbeitet: L am 1 Sep. 2017
I remade code1.m from scratch and named it code2.m. code2.m has the exact same code as code1.m
And in command window, I ran the two files and entered "which -all writePWMDutyCycle" and "path()". The attached pdfs are the results.
before_error.pdf is for code2.m and after_error.pdf is code1.m.
____________________________________________________________
EDIT/UPDATE:
I used excel to compare both results for path() and there were no differences.
Results for "which -all writePWMDutyCycle"
  • Before:
>> which -all writePWMDutyCycle
C:
\ProgramData\MATLAB\SupportPackages\R2017a\toolbox\matlab\hardware\supportpackages\ardui
noio\@arduino\arduino.m % arduino method
C:
\ProgramData\MATLAB\SupportPackages\R2017a\toolbox\matlab\hardware\supportpackages\ardui
noio\+arduinoio\+internal\MWProtocol.m % arduinoio.internal.MWProtocol method
C:
\ProgramData\MATLAB\SupportPackages\R2017a\toolbox\matlab\hardware\supportpackages\ardui
noio\+arduinoio\+internal\ProtocolBase.m % arduinoio.internal.ProtocolBase method
  • After:
>> which -all writePWMDutyCycle
'writePWMDutyCycle' not found.
@Donald Lee: I missed your comment so I will try that now
To confirm: after the problem occurs, does
C:\ProgramData\MATLAB\SupportPackages\R2017a\toolbox\matlab\hardware\supportpackages\arduinoio\@arduino\arduino.m
still exist?
If you execute the command
clear all
and run again, does it start working? How about if you
rehash toolboxcache
then does that start it working?
Another thing to try is
fclose('all')
when the problem has occurred.
It is certainly an odd situation.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Gefragt:

L
L
am 1 Sep. 2017

Bearbeitet:

am 2 Sep. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by