Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dóra Kocsis
dynare
Commits
2d1a1fc7
Commit
2d1a1fc7
authored
Jun 14, 2013
by
Stéphane Adjemian
Browse files
Added the possibility to rename the selected variables to be saved in a data file.
parent
7cff2a32
Changes
1
Hide whitespace changes
Inline
Side-by-side
matlab/datatomfile.m
View file @
2d1a1fc7
function
datatomfile
(
s
,
var_list
)
function
datatomfile
(
s
,
var_list
,
names
)
% function datatomfile (s,var_list)
% This optional command saves the simulation results in a text file. The name of each
% variable preceeds the corresponding results. This command must follow SIMUL.
...
...
@@ -6,6 +6,7 @@ function datatomfile (s,var_list)
% INPUTS
% s: data file name
% var_list: vector of selected endogenous variables
% names: vector of strings (alternative names for the endogenous variables in the data file)
%
% OUTPUTS
% none
...
...
@@ -32,14 +33,26 @@ function datatomfile (s,var_list)
global
M_
oo_
% Open the data file.
sm
=
[
s
,
'.m'
];
fid
=
fopen
(
sm
,
'w'
)
;
if
nargin
<
2
||
size
(
var_list
,
1
)
==
0
var_list
=
M_
.
endo_names
(
1
:
M_
.
orig_endo_nbr
,:);
end
n
=
size
(
var_list
,
1
);
ivar
=
zeros
(
n
,
1
);
if
nargin
==
3
if
~
isequal
(
size
(
var_list
,
1
),
n
)
error
(
'datatomfile:: Second and third arguments must have the same number of rows (variables)!'
)
end
else
names
=
var_list
;
end
% Get indices for the endogenous variables.
for
i
=
1
:
n
i_tmp
=
strmatch
(
var_list
(
i
,:),
M_
.
endo_names
,
'exact'
);
if
isempty
(
i_tmp
)
...
...
@@ -49,15 +62,15 @@ for i=1:n
end
end
% Save the selected data.
for
i
=
1
:
n
fprintf
(
fid
,[
M_
.
endo_
names
(
i
var
(
i
)
,:),
'
=
['
],
'\n'
)
;
fprintf
(
fid
,[
strtrim
(
names
(
i
,:)
)
,
'
=
['
],
'\n'
)
;
fprintf
(
fid
,
'\n'
)
;
fprintf
(
fid
,
'%15.8g\n'
,
oo_
.
endo_simul
(
ivar
(
i
),:)
'
)
;
fprintf
(
fid
,
'\n'
)
;
fprintf
(
fid
,
'];\n'
)
;
fprintf
(
fid
,
'\n'
)
;
end
% Close the data file.
fclose
(
fid
)
;
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment