Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dynare
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Frédéric Karamé
dynare
Commits
2098beb0
Commit
2098beb0
authored
12 years ago
by
Stéphane Adjemian
Browse files
Options
Downloads
Patches
Plain Diff
Added save method (m, mat, csv formats) in dynSeries class.
parent
73c96097
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
matlab/@dynSeries/save.m
+102
-0
102 additions, 0 deletions
matlab/@dynSeries/save.m
matlab/@dynSeries/subsref.m
+48
-0
48 additions, 0 deletions
matlab/@dynSeries/subsref.m
with
150 additions
and
0 deletions
matlab/@dynSeries/save.m
0 → 100644
+
102
−
0
View file @
2098beb0
function
save
(
A
,
basename
,
format
)
% Saves a dynSeries object on disk.
if
nargin
<
3
||
isempty
(
format
)
format
=
'csv'
;
end
if
nargin
<
2
||
isempty
(
basename
)
basename
=
inputname
(
1
);
end
switch
format
case
'm'
fid
=
fopen
([
basename
,
'.m'
],
'w'
);
fprintf
(
fid
,
'%% File created on %s.\n'
,
datestr
(
now
));
fprintf
(
fid
,
'\n'
);
fprintf
(
fid
,
'FREQ__ = %s;\n'
,
num2str
(
A
.
freq
));
fprintf
(
fid
,
'INIT__ =
''
%s
''
;\n'
,
A
.
init
.
format
);
fprintf
(
fid
,
'\n'
);
for
v
=
1
:
A
.
vobs
fprintf
(
fid
,
'%s = [\n'
,
A
.
name
{
v
});
fprintf
(
fid
,
'%15.8g\n'
,
A
.
data
(
1
:
end
-
1
,
v
));
fprintf
(
fid
,
'%15.8g];\n\n'
,
A
.
data
(
end
,
v
));
end
fclose
(
fid
);
case
'mat'
FREQ__
=
A
.
freq
;
INIT__
=
A
.
init
.
format
;
str
=
[];
for
v
=
1
:
A
.
vobs
str
=
[
str
,
A
.
name
{
v
}
' = A.data(:,'
num2str
(
v
)
');'
];
end
eval
(
str
);
save
([
basename
'.mat'
],
'INIT__'
,
'FREQ__'
,
A
.
name
{:});
case
'csv'
fid
=
fopen
([
basename
,
'.csv'
],
'w'
);
fprintf
(
fid
,
', %s'
,
A
.
name
{:});
fprintf
(
fid
,
'\n'
);
for
t
=
1
:
A
.
nobs
date
=
A
.
init
+
(
t
-
1
);
str
=
sprintf
(
', %15.8g'
,
A
.
data
(
t
,:));
fprintf
(
fid
,
'%s%s\n'
,
date
.
format
,
str
);
end
fclose
(
fid
);
end
%@test:1
%$ % Define a data set.
%$ A = [transpose(1:10),2*transpose(1:10)];
%$
%$ % Define names
%$ A_name = {'A1';'A2'};
%$
%$ % Instantiate a time series object.
%$ try
%$ ts1 = dynSeries(A,[],A_name,[]);
%$ save(ts1,[],'csv');
%$ t = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ T = all(t);
%@eof:1
%@test:2
%$ % Define a data set.
%$ A = [transpose(1:10),2*transpose(1:10)];
%$
%$ % Define names
%$ A_name = {'A1';'A2'};
%$
%$ % Instantiate a time series object.
%$ try
%$ ts1 = dynSeries(A,[],A_name,[]);
%$ save(ts1,[],'m');
%$ t = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ T = all(t);
%@eof:2
%@test:3
%$ % Define a data set.
%$ A = [transpose(1:10),2*transpose(1:10)];
%$
%$ % Define names
%$ A_name = {'A1';'A2'};
%$
%$ % Instantiate a time series object.
%$ try
%$ ts1 = dynSeries(A,[],A_name,[]);
%$ save(ts1,[],'m');
%$ t = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ T = all(t);
%@eof:3
This diff is collapsed.
Click to expand it.
matlab/@dynSeries/subsref.m
+
48
−
0
View file @
2098beb0
...
...
@@ -69,6 +69,9 @@ if length(S)==1 && isequal(S.type,'.')
us
=
builtin
(
'
subsref
'
,
ts
,
S
);
case
{'
log
','
exp
'}
%
Give
"dot access"
to
public
methods
.
us
=
feval
(
S
.
subs
,
ts
);
case
{'
save
'}
us
=
NaN
;
save
(
ts
);
otherwise
%
Extract
a
sub
-
object
by
selecting
one
variable
.
ndx
=
strmatch
(
S
.
subs
,
ts
.
name
);
if
~
isempty
(
ndx
)
...
...
@@ -119,9 +122,17 @@ end
if
(
length
(
S
)
==
1
)
&&
isequal
(
S
(
1
).
type
,
'
{}
'
)
us
=
extract
(
ts
,
S
(
1
).
subs
{
:
});
return
end
if
(
length
(
S
)
==
2
)
&&
isequal
(
S
(
1
).
subs
,
'
save
'
)
&&
isequal
(
S
(
1
).
type
,
'.'
)
&&
isequal
(
S
(
2
).
type
,
'
()
'
)
us
=
NaN
;
save
(
ts
,
S
(
2
).
subs
{
:
});
return
end
%
@test
:
1
%
$
%
Define
a
data
set
.
%
$
A
=
[
transpose
(
1
:
10
),
2
*
transpose
(
1
:
10
)];
...
...
@@ -306,3 +317,40 @@ end
%
$
T
=
all
(
t
);
%
@eof
:
6
%
@test
:
7
%
$
%
Define
a
data
set
.
%
$
A
=
[
transpose
(
1
:
10
),
2
*
transpose
(
1
:
10
)];
%
$
%
$
%
Define
names
%
$
A_name
=
{
'
A1
';'
A2
'
};
%
$
%
$
%
Instantiate
a
time
series
object
.
%
$
try
%
$
ts1
=
dynSeries
(
A
,[],
A_name
,[]);
%
$
ts1
.
save
;
%
$
t
=
1
;
%
$
catch
%
$
t
=
0
;
%
$
end
%
$
%
$
T
=
all
(
t
);
%
@eof
:
7
%
@test
:
8
%
$
%
Define
a
data
set
.
%
$
A
=
[
transpose
(
1
:
10
),
2
*
transpose
(
1
:
10
)];
%
$
%
$
%
Define
names
%
$
A_name
=
{
'
A1
';'
A2
'
};
%
$
%
$
%
Instantiate
a
time
series
object
.
%
$
try
%
$
ts1
=
dynSeries
(
A
,[],
A_name
,[]);
%
$
ts1
.
save
(
'
test_generated_data_file
','
m
'
);
%
$
t
=
1
;
%
$
catch
%
$
t
=
0
;
%
$
end
%
$
%
$
T
=
all
(
t
);
%
@eof
:
8
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment