Say we have data.m of Yours and a function foo.m that is about to use variables from there.
Turn the data.m into this form:
function[]=data() % defines a function with no output nor input
a1=[1 2 3];
b2='string';
%Your definitions and other code
save('DataFile.mat'); % save EVERY varible used in the code with it's name
Then in foo.m
function[]=foo()
load('DataFile.mat'); % Load all variables saved in DataFile.mat
disp(b2);
You can also prevent temporary variables to be saved with the mandatory ones by deleting them just before save command by clear temp1 temp2
If you want to save some variables, say a1 in one file and other in different file You can use save('DataFile.mat','a1')
If you want to load specific variables You can use load('DataFile.mat','b1')
data.m? Do you mean you want them in your workspace but you don't want the code that creates them in your script? If the first case, then use a mat file, just read the docs ofsave. If the second case then you should be creating them in a function.