-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.m
More file actions
121 lines (93 loc) · 3.47 KB
/
example.m
File metadata and controls
121 lines (93 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
%% Example Script
% This Script is meant to demonstrate the capabilities of the PlotID tool.
%% Clear Environment
clear; clc; close all;
try
delete testdata2.h5;
end
%% Set ProjectID
% ProjectID can also be set in the config file
% Leave empty for using the ID from the config file
ProjectID = 'Example';
%% Data
% only necessary for this example
% Creating Random Data to use as data-file
x = linspace(0,7); y = rand(1,100)+2;
dataset1 = 'test_data.mat';
% Use absolute paths for good practise
dataset1 = fullfile(pwd,dataset1);
save(dataset1,'x','y');
% some data for the .h5 file
x1 = linspace(0,2*pi); y1 = sin(x1)+2;
% define filepath & name
dataset2 = 'testdata2.h5';
dataset2 = fullfile(pwd,dataset2);
fpath = dataset2;
% create hdf5 file and dataset > write data to hdf5 file / dataset
h5create(fpath, "/x1", size(x1), "Datatype", class(x1))
h5create(fpath, "/y1", size(y1), "Datatype", class(y1))
h5write(fpath, "/x1", x1)
h5write(fpath, "/y1", y1)
%% function calls
% Place for post-processing of the data, or additional related code.
% example_fcn is a dummy function to show the functionality
a = 1; a = example_fcn(a);
% Uncomment to include the Statistics and Machine learning Toolbox
% p = betacdf(0.5,1,1); % to test toolboxes
%% Plotting
% This is still part of a normal script to produce plots.
% Make sure to save each figure in a variable
% to pass it to PlotID-functions.
fig(1) = figure;
plot(x,y,'-k');
box off; hold on;
plot(x1,y1,'-r');
set(gca, 'TickDir', 'out', 'YLim', [0,4]);
%% Example 1: single plot based on two data-sets
%% Tag the plot
% PlotID Implementation starts here.
% TagPlot adds a visible ID to the figure(s) and to the figures property
% 'Tag'
[fig, IDobj] = PlotID.TagPlot(fig, 'ProjectID', ProjectID);
%% Publishing
% Second part of plotID
% The functions needs the file location of the script, the location of the
% data and the figure and can take several options (see readme).
% filename of the m.script, extension must be added!
scriptPath = [mfilename('fullpath'),'.m'];
% file names of the datasets
%(defined above:) dataset1 = 'test_data.mat'; dataset2 = 'testdata2.h5'
locations = {dataset1,dataset2} ; % don't forget the extension
locations = {string(dataset1),dataset2}
%call publishing
PlotID.Publish(locations,scriptPath, fig(1), 'Location', 'local' ,'Method','individual')
%% Example 2: multiple plots plot, all based on dataset2 (hdf5)
% for individual data-sets, use an appropriate array
fig(2) = figure;
plot(x,y,'-b');
box off; hold on;
plot(x1,y1,'--k');
set(gca, 'TickDir', 'out', 'YLim', [0,4]);
% tag both plots
[fig, IDs] = PlotID.TagPlot(fig,'ProjectID', ProjectID);
% data locations
script = [mfilename('fullpath'),'.m']; % filename of the m.script
% file names of the datasets
rdata = dataset2 ; % don't forget the extension
% publsihing via a for-loop
for i=1: numel(fig)
PlotID.Publish(rdata, script, fig(i), 'Location', 'local',...
'Method','individual');
end
%% Second Plot with identical data to test centralized method
% A central data folder is used for saving the research data files, the
% subfolders contain linked hdf5-files (if hdf5 is used). This is
% recommended, if many plots are made from the same data set. Attention,
% the linked HDF5 will not work when a subfolder was moved or the data
% folder was deleted
fig2 =figure;
plot(x,y,'-k');
hold on
plot(x1,y1,'-r');
[fig2, ID] = PlotID.TagPlot(fig2,'ProjectID', ProjectID);
PlotID.Publish(locations,scriptPath, fig2, 'Location', 'local','Method','centralized')