how to write a struct to a .xls or txt file

1 次查看(过去 30 天)
station = struct(...
'name', {'CD2', 'GYA', 'GOM', 'XAN', 'LZH','KMI', 'LSA','MDJ','WMQ','CNS', 'GUL', 'GZH', 'HEF', 'QZH', 'WHN','WZH'},...
'Jingdu',{103.76 ,106.66,103.84,94.81,108.92,102.74,91.10,129.59,87.69,112.59,110.12,113.65,117.17,118.60,114.35,120.40},...
'Weidu',{30.91, 26.46, 36.09, 36.20, 34.03,25.12,29.73,44.62,43.65,28.12,25.12,23.65,31.52,24.94,30.54,27.55});
1.how can i save it into a xls file , and then load it from the xls file?

回答(1 个)

Image Analyst
Image Analyst 2014-4-18
编辑:Image Analyst 2014-4-18
Use struct2table() and writetable():
t = struct2table(station)
writetable(t, 'station.xlsx');
  5 个评论
Roger
Roger 2014-4-18
in my code , i need a struct type variable,so i creat a xls file which saves datas i need,but creat a structure in my code , when i need to use it , i just load it ; sometimes data saved in xls file should be changed ,like appending some data, i just changed the xls file . I just want somebody can change data for his needs from xls file and not need to read my code ,or change from code.
Image Analyst
Image Analyst 2014-4-18
OK, so you read it in with some unspecified function (probably xlsread) and then you convert the array or cell array into a structure for convenience elsewhere in your program. OK fine. If you then change that structure and want to save it back out in the original form back to your Excel workbook file, you're going to have to either change your original cell array that you read in, or else use struct2table. Then you're going to have to write back that changed variable to the workbook file with xlswrite() or writetable().

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by