MATLAB: How can i save multiple variables in a text file, including the variable names

namessavetxtvariables

I have a workspace with 30 variables, all sized 8×1.
I would like to save all of them in a .txt file, including their name.
The command I am using is:
save( 'filename.txt' , '-ASCII' );
It saves the variable values as intended, but not the variable names alongside their values.
Any help would be most welcome! Thank you in advance!

Best Answer

myfilepath = 'C:\myfile.txt';
fid = fopen(myfilepath, 'wt');
fprintf(fid, '% this is the beginning of my file');
fprintf(fid, 'var1 = %d ',evalin('base',var1)); % if var1 is double
fclose(fid);
you can use "whos" to find what variables u have in base workspace...
Related Question