MATLAB: How to make a variable in one .m file make changes in another .m file

image processingMATLABvariables

Hi, I change the variable of one .m file and want that this number be automatically rewritten for another variable in another .m file.
For example, I open the file:
open cpcorr.m;
and change the value in line 76 as below:
CORRSIZE = 4;
Now I have a new newfile.m with the variable
CS=CORRSIZE;
Thus, when I change the value of CORRSIZE in cpcorr.m, I wish also that the value of CS in file1.m be automatically changed, for this particular example, CS would equal 4.
I hope someone knows how to fix this.
Thanks in advance for your help
Emerson

Best Answer

You can't do it if all you do is to change the text in the m-file. After all, an m-file is stored simply as a flat text file on disk. One text file sitting there on disk is not going to know that it needs to change itself if some other file somewhere on disk changed itself. However if you run the m-file, then you can put code in it to change the variable value in the other m-file. Look at the assignin() function.