How to save workspace variables and values a s binary file
5 次查看(过去 30 天)
显示 更早的评论
I wrote a code and want to save all workspace's variables and their values as a .txt file or other formats as a binary file just to print them out. Note I need both variable names and values.
4 个评论
Walter Roberson
2018-3-5
Are all of the variables pure numeric? Are they all row vectors? Are some of them 2D arrays? Are some of them 3D arrays?
采纳的回答
Image Analyst
2018-3-5
Try this and see if it does what you want:
% Get list of all variables in current workspace.
s = whos
% Print out variables one by one to the command window.
% Essentially we're using eval() to put each variable on the command line.
% When you do that, MATLAB will report the value to the command line,
% just as if you had manually typed the variable name yourself on the command line.
for k = 1 : length(s)
thisVariable = s(k).name;
eval(thisVariable)
end
2 个评论
Image Analyst
2018-3-5
Try this:
% Get list of all variables in current workspace.
s = whos
% Print out variables one by one to the command window.
% Essentially we're using eval() to put each variable on the command line.
% When you do that, MATLAB will report the value to the command line,
% just as if you had manually typed the variable name yourself on the command line.
for k = 1 : length(s)
thisVariable = s(k).name;
thisValue = eval(thisVariable);
fprintf('%f is the value for %s.\n', thisValue, thisVariable);
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!