MATLAB: Need help about calling m file into Matlab command window/workspace …

loadm-file

My version of the matlab is r2010b!
I have 2 m-files, the main one - it first runs in a command window (main.m), and the other one (data.m), which is called during the execution of the first - for loading data ...
main.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear
clc
while 1
edit ('data.m')
disp ('After the completion of data entry, press 1,');
disp ('To change the input data, press 0');
k = input ('');
if (k == 1)
fprintf ('\ n Loading data ..... \ n \ n')
data
break;
end
end
s = a * 10
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear
a = [1 2 3 4 5]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
First I run main.m --- it opens data.m --- I change vector a (eg a = [10 20 30]) --- and save it (click on the save button) --- BUT INSTEAD OF LOADING NEW-Changed vector a = [10 20 30], main.m loads the previous one (a=[1 2 3 4 5] ) from data.m !!!!!
Only when I restart main.m then it loads a changed vector --- [10 20 30 ]................
How do I fix this? tnx
Nikola

Best Answer

rehash solves it!!! tnx to Walter Roberson and others ;)
main.m
clear
clc
while 1
edit ('data.m')
disp ('After the completion of data entry, press 1,');
disp ('To change the input data, press 0');
k = input ('');
if (k == 1)
fprintf ('Loading data...')
rehash %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data
break;
end
end
s = a * 10
Related Question