M-file edited and saved by external editor is not recognized by MATLAB

2 views (last 30 days)
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

Answers (1)

Cam Salzberger
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
tuncel3
tuncel3 on 13 Dec 2017
I understand you, but I think its about something else. I edit the code in notepad++ and save. In MATLAB editor, code changes automatically because it is edited externally. Now if I click reset button on GUI, changes does not take effect. If I go to MATLAB editor and click save, then click reset button on GUI, changes take effect. This means MATLAB recognizes file edited externally only if you click save in MATLAB or run it from RUN button on MATLAB tool buttons. If you edit a script with an external editor and run the script from a GUI button, changes does not take effect. Clear classes, rehash or rehas toolboxcache does not work. There must be some kind of fix for this problem, or an option. Because notepad++ is better than MATLAB editor. For example there is duplicate line shortcut and column mode editing in notepad++.
Andrew Janke
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

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!