Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

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

Asked by Zacharias Kandylakis on 19 Nov 2012

I have a workspace with 30 variables, all sized 8x1.

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!

1 Comment

Azzi Abdelmalek on 19 Nov 2012

why don' t save them to mat file? is there any reason?

Zacharias Kandylakis

Products

No products are associated with this question.

1 Answer

Answer by Babak on 19 Nov 2012
 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...

0 Comments

Babak

Contact us