How to selectively save the names and values of some workspace variables to a CSV file?
조회 수: 9(최근 30일)
표시 이전 댓글
Consider the following
a = 3; b=7; c=5; d=9;
save('test.mat')
data = load('test.mat');
toSave = { 'b' ; 'c' };
writecell( horzcat( toSave , <missing code> ) ,'myfile.csv')
what should be the <missing code> in order to have the content of myfile.csv to be
b , 7
c , 5
?
채택된 답변
Rik
2020년 9월 15일
This should do the trick. If the variables aren't scalars the results might not be what you want.
a = 3; b=7; c=5; d=9;
save('test.mat')
data = load('test.mat');
toSave = { 'b' ; 'c' };
s=struct;
for n=1:numel(toSave)
s.(toSave{n})=data.(toSave{n});
end
writecell( horzcat( toSave , struct2cell(s) ) ,'myfile.csv')
추가 답변(1개)
참고 항목
범주
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!