M-file edited and saved by external editor is not recognized by MATLAB
2 views (last 30 days)
Show older comments
Below code creates a reset button. When I change the szx variable in notepad++ and press reset button on the gui, the gui size does not change. I have to click run button on MATLAB editor to apply changes. How can I make MATLAB recognize changes made in an external editor. I tried all the suggestions on these forum, like rehash. Nothing works.
function gui_ind
clear,clc,close all
f1=figure(1)
scr_sz=get(0,'ScreenSize')
szx=200
szy=300
posx=130;
posy=scr_sz(4)-60-szy;
set(gcf,'position',[posx posy szx szy]);
rst_b = uicontrol('string','Reset','style','pushbutton','position',...
[szx-60 0 60 20],'callback',{@rst_e_cbf});
px=0;py=szy;
VA_t = uicontrol('string','VA','style','text','position',[5 szy-20 30 18],...
'HorizontalAlignment','left');
VA_e = uicontrol('string','','style','edit','position',[25 szy-20 60 20],...
'callback',{@VA_e_cbf},'HorizontalAlignment','left');
function rst_e_cbf(varargin)
gui_ind()
end
end
0 Comments
Answers (1)
Cam Salzberger
on 13 Dec 2017
Edited: Cam Salzberger
on 13 Dec 2017
Hello Mehmet,
MATLAB caches code so that it is able to run faster. Otherwise, every time you call a function, it would have to re-parse the text to know what to do. That's a fairly unsustainable model.
Generally, when you make changes to code, I'd recommend re-running the code anyway. It's a requirement in almost any other coding language that I can think of, because those languages compile the code into something machine-readable. MATLAB doesn't explicitly have a compilation step, but it still caches the instructions in a more compact manner.
If simply reopening the GUI doesn't work for you, you can also try clearing out class definitions. This is usually more applicable if you change something in a class definition, while you have an object of that class instantiated. To do this, run:
clear classes
You may need to rehash the cache to get the updated files. First try simply:
rehash
If that doesn't do it, go for the full:
rehash toolboxcache
Finally, there's always the option to close and open MATLAB. If that still doesn't catch the changed definition, then you likely have an older copy of that file somewhere higher on the MATLAB path.
You may be able to keep the GUI open and use clear classes or rehash without issue. You're welcome to try it, but I usually close and rerun the GUI just to be safe.
-Cam
2 Comments
Andrew Janke
on 24 Jan 2021
Hi Cam!
I remember back in the day when I was working on Linux, you had to configure Matlab to do filesystem polling to notice externally-changed .m files, through some sort of Matlab preference. But I can't remember what it was. Any chance you know what that setting is?
Cheers,
Andrew
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!