Outputting a variable (1*1) struct in txt file

1 次查看(过去 30 天)
Hello everybody
I run the regression analysis and have got a varialble with reg [1*1 struct] I want to output this in a txt file but its giving me an error this is the out out
reg =
FitParameters: '-----------------'
PowerMatrix: [28x6 double]
Scores: [14152x28 double]
PolynomialExpression: [28x2 table]
Coefficients: [28x1 double]
yhat: [14152x1 double]
Residuals: [14152x1 double]
GoodnessOfFit: '-----------------'
RSquare: 0.6721
MAE: 0.0693
MAESTD: 0.0593
Normalization: '1-to-1 (Default)'
LOOCVGoodnessOfFit: '-----------------'
CVRSquare: 0.6684
CVMAE: 0.0696
CVMAESTD: 0.0600
CVNormalization: '1-to-1 (Default)'
Can anybody help me with this as save('X.txt...') is not working
  2 个评论
Walter Roberson
Walter Roberson 2015-8-21
What format do you want for the output, taking into account that part of the data involves a 14152 x 28 matrix ?
amberly hadden
amberly hadden 2015-8-21
I would like to get .txt or xlsx or any out put which can later be open without matlab

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2015-8-21
Xls might not make sense unless you use one Sheet per variable.
I suggest looping over the fields of the structure. For each write out the fieldname then the class() of the data then the array dimensions all on one line. Next line write the values out row by row, delimited, all columns on each line. For 2d arrays the number of rows in the file would match the number of rows in the matrix. You only use 2d in your sample output.
With this kind of arrangement, the heading for each variable tells you how many lines of data follow so you can gulp them all in in one textscan call or otherwise easily seek for the line you need.
  2 个评论
Walter Roberson
Walter Roberson 2015-8-21
Though the table() object will take a bit more effort.
amberly hadden
amberly hadden 2015-8-21
编辑:Walter Roberson 2015-8-22
Thanks walter much appreciated. table() is again creating a 1*1 struct.
Also I think I can modify code in a way that it output table which can be then expoted
reg = struct('FitParameters','-----------------','PowerMatrix',A,'Scores',Scores, ...
'PolynomialExpression',PolyExp,'Coefficients',b, 'yhat', yhat, 'Residuals', r, ...
'GoodnessOfFit','-----------------', 'RSquare', r2, 'MAE', mae, 'MAESTD', maestd, ...
'Normalization',NormalizationSwitch,'LOOCVGoodnessOfFit','-----------------', 'CVRSquare', ...
CVr2, 'CVMAE', CVmae, 'CVMAESTD', CVmaestd,'CVNormalization',NormalizationSwitch);
so instead of struct I can just use {} but its not including variable values.. I will keep trying this and many thanks for your help

请先登录,再进行评论。

类别

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