From c8cd0a06ced8afb35d1b8cdde71bf8dd39b1298b Mon Sep 17 00:00:00 2001
From: Marco Ratto <marco.ratto@ec.europa.eu>
Date: Thu, 29 Oct 2020 18:27:24 +0100
Subject: [PATCH] allow to export expand groups to excel (instead than plotting
 them)

---
 matlab/expand_group.m        | 12 ++++++++++--
 matlab/graph_decomp.m        |  2 ++
 matlab/graph_decomp_detail.m |  2 ++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/matlab/expand_group.m b/matlab/expand_group.m
index 0992e4967d..a216b51b1a 100644
--- a/matlab/expand_group.m
+++ b/matlab/expand_group.m
@@ -1,4 +1,4 @@
-function expand_group(use_shock_groups,var_list_, ic)
+function expand_group(use_shock_groups,var_list_, ic, no_graph)
 % function expand_group(use_shock_groups,var_list_, ic)
 % Expands shocks contributions out of a group of shocks
 %
@@ -27,6 +27,9 @@ function expand_group(use_shock_groups,var_list_, ic)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
+if nargin<4
+    no_graph=0;
+end
 filename = get(gcf,'filename');
 [filepath, name, ext]=fileparts(filename);
 M = evalin('base','M_');
@@ -56,7 +59,12 @@ M.exo_names = mydata.exo_names;
 options.plot_shock_decomp.interactive=0;
 options.plot_shock_decomp.expand=1;
 options.plot_shock_decomp.nodisplay=0;
-options.plot_shock_decomp.write_xls=0;
+if no_graph
+    options.no_graph.plot_shock_decomposition=1;
+    options.plot_shock_decomp.write_xls=1;
+else
+    options.plot_shock_decomp.write_xls=0;
+end
 %% set optimal colormap
 func = @(x) colorspace('RGB->Lab',x);
 MAP = distinguishable_colors(length(shocks)+1,'w',func);
diff --git a/matlab/graph_decomp.m b/matlab/graph_decomp.m
index 20eb7c1083..553f4060b9 100644
--- a/matlab/graph_decomp.m
+++ b/matlab/graph_decomp.m
@@ -237,6 +237,8 @@ for j=1:nvar
                 browse_menu = uimenu(c,'Label','Browse group');
                 expand_menu = uimenu(c,'Label','Expand group','Callback',['expand_group(''' mydata.plot_shock_decomp.use_shock_groups ''',''' mydata.plot_shock_decomp.orig_varlist{j} ''',' int2str(i) ')']);
                 set(expand_menu,'UserData',mydata,'Tag',['group' int2str(i)]);
+                save_expand2xls_menu = uimenu(c,'Label','Export group to xls','Callback',['expand_group(''' mydata.plot_shock_decomp.use_shock_groups ''',''' deblank(mydata.plot_shock_decomp.orig_varlist(j,:)) ''',' int2str(i) ', 1)']);
+                set(save_expand2xls_menu,'Tag',['xls_group' int2str(i)]);
                 for jmember = mydata.shock_group.shocks
                     uimenu('parent',browse_menu,'Label',char(jmember))
                 end
diff --git a/matlab/graph_decomp_detail.m b/matlab/graph_decomp_detail.m
index 2a3aa216e7..24397230b0 100644
--- a/matlab/graph_decomp_detail.m
+++ b/matlab/graph_decomp_detail.m
@@ -243,6 +243,8 @@ for j=1:nvar
                     browse_menu = uimenu(c,'Label','Browse group');
                     expand_menu = uimenu(c,'Label','Expand group','Callback',['expand_group(''' mydata.plot_shock_decomp.use_shock_groups ''',''' mydata.plot_shock_decomp.orig_varlist{j} ''',' int2str(ic) ')']);
                     set(expand_menu,'UserData',mydata,'Tag',['group' int2str(ic)]);
+                    save_expand2xls_menu = uimenu(c,'Label','Export group to xls','Callback',['expand_group(''' mydata.plot_shock_decomp.use_shock_groups ''',''' deblank(mydata.plot_shock_decomp.orig_varlist(j,:)) ''',' int2str(ic) ', 1)']);
+                    set(save_expand2xls_menu,'Tag',['xls_group' int2str(ic)]);
                     for jmember = mydata.shock_group.shocks
                         uimenu('parent',browse_menu,'Label',char(jmember))
                     end
-- 
GitLab