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

1 visualización (últimos 30 días)
amberly hadden
amberly hadden el 20 de Ag. de 2015
Editada: Walter Roberson el 22 de Ag. de 2015
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 comentarios
Walter Roberson
Walter Roberson el 21 de Ag. de 2015
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 el 21 de Ag. de 2015
I would like to get .txt or xlsx or any out put which can later be open without matlab

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 21 de Ag. de 2015
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 comentarios
Walter Roberson
Walter Roberson el 21 de Ag. de 2015
Though the table() object will take a bit more effort.
amberly hadden
amberly hadden el 21 de Ag. de 2015
Editada: Walter Roberson el 22 de Ag. de 2015
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

Iniciar sesión para comentar.

Categorías

Más información sobre Structures en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by