From 835a70f6e9e1f127906fd68ef45ebe3d873b074e Mon Sep 17 00:00:00 2001
From: "M. Hock" <martin.hock@fst.tu-darmstadt.de>
Date: Fri, 18 Feb 2022 11:56:13 +0100
Subject: [PATCH] implemented handling of multiple structures

---
 +PlotID/@dataPath/dataPath.m  |  2 +-
 +PlotID/@dataPath/vars2file.m | 17 +++++++++++++----
 Examples/PlotID_variables.m   |  5 ++---
 README.md                     |  2 +-
 4 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/+PlotID/@dataPath/dataPath.m b/+PlotID/@dataPath/dataPath.m
index cb52877..67c3ede 100644
--- a/+PlotID/@dataPath/dataPath.m
+++ b/+PlotID/@dataPath/dataPath.m
@@ -66,7 +66,7 @@ classdef dataPath < handle
         
         function cleanTmpFile(obj)
             if ~isempty(obj.tmpPath)
-                delete(obj.tmpPath); 
+                delete(obj.tmpPath{:}); 
             end
         end
 
diff --git a/+PlotID/@dataPath/vars2file.m b/+PlotID/@dataPath/vars2file.m
index d82fff0..f7c2ac3 100644
--- a/+PlotID/@dataPath/vars2file.m
+++ b/+PlotID/@dataPath/vars2file.m
@@ -9,15 +9,24 @@ if ~isfolder(tmpDir)
 end
 obj.tmpPath = fullfile(tmpDir,[obj.ID,'_vars.mat']); 
 
-% save only the first struct (intended) 
-struct = obj.DataPaths{isStruct};
-save(obj.tmpPath,'-struct','struct');
+% save each of the structs 
+for i=1:numel({obj.DataPaths{isStruct}})
+    struct = obj.DataPaths{isStruct};
+    if i==1
+        save(obj.tmpPath,'-struct','struct');
+        obj.tmpPath = {obj.tmpPath};
+    else
+        tmpPath = fullfile(tmpDir,[obj.ID,'_vars',num2str(i),'.mat']);
+        save(tmpPath,'-struct','struct');
+        obj.tmpPath{end+1}=tmpPath;
+    end
+end
 
 % remove variable from Datapath
 obj.DataPaths(isStruct) = [];
 % add tmppath as Datapath
 
-obj.DataPaths{end+1} = obj.tmpPath;
+obj.DataPaths = horzcat(obj.DataPaths, obj.tmpPath);
 
 end
 
diff --git a/Examples/PlotID_variables.m b/Examples/PlotID_variables.m
index e24704d..1d34b74 100644
--- a/Examples/PlotID_variables.m
+++ b/Examples/PlotID_variables.m
@@ -15,10 +15,9 @@ plot(x,y,'-k'); box off; set(gca, 'TickDir', 'out', 'YLim', [0,4]);
 
 %%  ----  2. Publishing -----
 % You can pass an abitrary number of variables to Publish.
-% IMPORTANT: they must be collected and passed in ONE struct
-% if multiple structs are passed, only the first one will be stored!
+% Passing multiple structs will create multiple data files.
 % You can additionally add datapaths and combine the methods.
-% Passing multiple structs
+
 
 %Example: Passing the variables x,y to publish
 
diff --git a/README.md b/README.md
index 1386a0c..4809824 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@ The **ProjectID** is your custom project number, it well be the prefix of the ID
 `PlotID.Publish(DataPaths,scriptPath,  figure, options)`
 
 `scriptPath` contains either the path to the script, this can be provided with the simple call of `scriptPath = [mfilename('fullpath'),'.m']` or the script or function name that is used for creating your plot. \
-`DataPaths` contains the path(s) to the research data, for multiple files you can use a cell array (they must be at the path). It is also possible to pass an arbitrary number of variables. All variables **must be** passed in **one** struct. \
+`DataPaths` contains the path(s) to the research data, for multiple files you can use a cell array (they must be at the path). It is also possible to pass an arbitrary number of variables as struct.  \
 `figure` is the figure that should be published.
 
 **Please take also a look on the examples provided in the Example folder**.
-- 
GitLab