bla
bla

Reputation: 26069

obtaining the info in Matlab's workspace window \ workspace panel

I would like to document each time I run a specific script that I have, in particular a list of variables and their values.

Matlab has the function who for obtaining the variables name, and whos to get more info, but what I really want is just to save the info that I already have in the "workspace panel" that is visible on the screen, where the names and values of various variables are written (sometimes it's actually the value, sometimes the size and class are mentioned). just type workspace at the command prompt, if you don't understand what I mean.

I know I can just save the entire workspace as a .mat file (and I do so), but I just want a small txt file with that info so I wont need to load matlab to see what's in that file.

Is there a simple way you are aware of that allows to access that info?

Upvotes: 0

Views: 89

Answers (2)

CitizenInsane
CitizenInsane

Reputation: 4855

To add on @il_raffa answer, maybe another solution to display variable values just like they appear in workspace browser is to use workspacefunc('getshortvalue', eval(varname)) instead of direct call to eval(varname):

v = whos();
for idx = 1:length(v)
    name = v(idx).name;
    value = workspacefunc('getshortvalue', eval(name));
    fprintf(1, '%s\t\t\t\t\t\t%s\n', name, value); 
end

Upvotes: 1

il_raffa
il_raffa

Reputation: 5190

You can use the diary command to save the information on a .txt file:

Updated answer

You can use the output of whos whitin a loop which uses eval to display the value of the variable and store it in the diary file.

Updated code

clear all

a=peaks;
b=magic(4);
c=size(b);
d=length(a);
v_str.n=1

diary('w.txt')
whos
zzz=whos;
for i=1:length(zzz)
   eval([zzz(i).name])
end
diary off

Hope this helps.

Upvotes: 1

Related Questions