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

3 ビュー (過去 30 日間)
Zacharias Kandylakis
Zacharias Kandylakis 2012 年 11 月 19 日
コメント済み: Tongyao 2023 年 5 月 4 日
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!
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 11 月 19 日
why don' t save them to mat file? is there any reason?
Tongyao
Tongyao 2023 年 5 月 4 日
not op, but my code generated around 50 variables. I would love to have a snapshot of them and look at them later (it doesn't matter for me to save the details of structures/matrixes). I don't want them to be in .mat format because I don't want to override the workspace generated by a slightly different code. I can print the workspace to pdf, but saving them with a txt file would be nicer. I did this one but now I now forget how to do that.

サインインしてコメントする。

採用された回答

Babak
Babak 2012 年 11 月 19 日
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 件)

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by