-
Notifications
You must be signed in to change notification settings - Fork 2
/
NanoPlotter_main.m
220 lines (184 loc) · 8.38 KB
/
NanoPlotter_main.m
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
%% NanoPlotter_main
% By Robert J Scales
%
% DataTypeList,PlotDataTypes,figHandles are needed by NanoMeaner
function [DataTypeList,PlotDataTypes,figHandles] = NanoPlotter_main(debugON,FileStuctures,PlotAesthetics,FormatAnswer)
%% Setting Up
fprintf('NanoPlotter_main: Started!\n');
% Converts from string array that is needed to save it into a
% cell array for further processing. 1st array should be indent depth
% in nm! Hence not included in this.
DataTypeList = cellstr(FileStuctures{1}.varNames(2:end));
% DataTypeList = {'Load (mN)','Time (s)','Harmonic Contact Stiffness (N/m)','Hardness (GPa)','Youngs Modulus (GPa)'};
PlotDataTypes = ChooseDataToPlot(DataTypeList);
if debugON == true
disp('PlotDataTypes = ...');
disp(PlotDataTypes);
end
for i = 1:length(DataTypeList)
currDataType = DataTypeList{i};
split_DataTypeList = split(currDataType);
fig_Name = split_DataTypeList{1};
figure('Name',fig_Name,'windowstate','maximized');
end
figHandles = findobj('Type', 'figure'); % Gets the current figure handles
NumberOfFiles = length(FileStuctures);
% The first column is the indent depth column
Y_Axis_Labels = DataTypeList; % y-axis labels
X_Axis_Label = 'Indent Depth (nm)'; % x-axis label
legendLocation = 'southeast';
capsize = PlotAesthetics.capsize;
linewidth = PlotAesthetics.linewidth;
facealpha = PlotAesthetics.facealpha;
if debugON == true
disp('DEBUG ON!')
disp('Initial figure handles are:');
disp(figHandles);
fprintf('Number of loaded files = %d\n',NumberOfFiles)
end
%% Main Loop
for FileNum = 1:NumberOfFiles
CurrentIDName = FileStuctures{FileNum,1}.DataIDName;
fprintf('Currently working on %s\n',CurrentIDName);
ValueData = FileStuctures{FileNum,1}.ValueData;
XDataCol = FileStuctures{FileNum,1}.XDataCol;
ErrorData = FileStuctures{FileNum,1}.ErrorData;
NumberOfSamples = size(ValueData,3);
SampleNameList = FileStuctures{FileNum,1}.SampleNameList;
for i=1:NumberOfSamples
LegendName = SampleNameList(i);
currValueData = ValueData(:,:,i);
currErrorData = ErrorData(:,:,i);
if debugON == true
disp('Current Value Data = ...')
disp(currValueData);
end
if strcmp(FormatAnswer,'Line + Error Region') == true || strcmp(FormatAnswer,'Line') == true
Color = LinePlotting(debugON,currValueData,PlotDataTypes,figHandles,LegendName,linewidth,XDataCol);
elseif strcmp(FormatAnswer,'Line + Error Bars') == true
ErroBarPlotting(debugON,currValueData,currErrorData,PlotDataTypes,figHandles,LegendName,linewidth,capsize,XDataCol)
else
errordlg(sprintf('Plotting mode does not match with any known options!\n = "%s"',FormatAnswer));
return
end
if strcmp(FormatAnswer,'Line + Error Region') == true
% This pre-processes the input data so that it can plot the error
% region using the output data (EFP).
ErrorRegionPlotting(debugON,currValueData,currErrorData,PlotDataTypes,figHandles,Color,facealpha,XDataCol)
end
clear LegendName currValueData currErrorData Color
end
clear CurrentIDName ValueData ErrorData NumberOfSamples SampleNameList Color
end
figureFormatting(PlotDataTypes,figHandles,Y_Axis_Labels,X_Axis_Label,legendLocation)
figureClosing(debugON,DataTypeList,PlotDataTypes);
fprintf('NanoPlotter_main: Complete!\n\n');
end
%% Functions
function PlotDataTypes = ChooseDataToPlot(DataTypeList)
PromptString = {'Select what data to plot against depth:','Multiple can be selected at once.'};
[PlotDataTypes,~] = listdlg('PromptString',PromptString,'SelectionMode','multiple','ListString',DataTypeList);
end
function Color = LinePlotting(debugON,currValueData,PlotDataTypes,figHandles,LegendName,linewidth,XDataCol)
NumberOfPlots = length(PlotDataTypes);
for j = 1:NumberOfPlots
currDataNum = PlotDataTypes(j); % e.g. = 3 if HCS selected
% currFigHandle = figHandles(currDataNum);
figure(currDataNum)
columnNum = currDataNum+1;
Data = plot(currValueData(:,XDataCol),currValueData(:,columnNum),'DisplayName',LegendName,'LineWidth',linewidth);
Color = Data.Color;
hold on
if debugON == true
fprintf('LinePlotting\nj = %d\tcurrDataNum = %d\nCurrent figure handle:...\n',j,currDataNum)
end
end
end
function ErroBarPlotting(debugON,currValueData,currErrorData,PlotDataTypes,figHandles,LegendName,linewidth,capsize,XDataCol)
NumberOfPlots = length(PlotDataTypes);
for i = 1:NumberOfPlots
currDataNum = PlotDataTypes(i); % e.g. = 3 if HCS selected
% currFigHandle = figHandles(currDataNum);
figure(currDataNum)
columnNum = currDataNum+1;
errorbar(currValueData(:,XDataCol),currValueData(:,columnNum),currErrorData(:,columnNum),'DisplayName',LegendName,'LineWidth',linewidth,'CapSize',capsize);
hold on
end
end
function ErrorRegionPlotting(debugON,currValueData,currErrorData,PlotDataTypes,figHandles,Color,facealpha,XDataCol)
NumberOfPlots = length(PlotDataTypes);
for i = 1:NumberOfPlots
currDataNum = PlotDataTypes(i); % e.g. = 3 if HCS selected
% currFigHandle = figHandles(currDataNum);
figure(currDataNum)
columnNum = currDataNum+1;
XData = currValueData(:,XDataCol);
YData = currValueData(:,columnNum);
YErr = currErrorData(:,columnNum);
[EFP,~] = PatchPreProcessorFunc(XData,YData,YErr);
ErrBarFill = patch('XData',EFP.X,'YData',EFP.Y,'FaceColor',Color,'FaceAlpha',facealpha,'EdgeColor','none');
set(get(get(ErrBarFill,'Annotation'),'LegendInformation'),'IconDisplayStyle','off'); %Does not plot it on legend
hold on
end
end
function figureFormatting(PlotDataTypes,figHandles,DataTypeList,X_Axis_Label,legendLocation)
NumberOfPlots = length(PlotDataTypes);
for i = 1:NumberOfPlots
currDataNum = PlotDataTypes(i); % e.g. = 3 if HCS selected
% currFigHandle = figHandles(currDataNum);
figure(currDataNum)
ylabel(DataTypeList(currDataNum));
xlabel(X_Axis_Label);
YLIM = ylim();
XLIM = xlim();
ylim([0,NewLimit(YLIM(2))]);
xlim([0,NewLimit(XLIM(2))]);
grid on;
legend('location',legendLocation);
end
end
function NewLimitValue = NewLimit(currLimit)
addOn = floor(log10(currLimit))-1;
NewLimitValue = currLimit+(10^addOn);
disp(currLimit);
disp(NewLimitValue);
end
function [EFP,OutArray] = PatchPreProcessorFunc(XData,YData,YErr)
fprintf('PatchPreProcessorFunc: Started!\n');
CombinedArray = [YData,YErr];
% This creates a logical array from which we will fill in if it is
% being flagged as not suitable data.
TF_isnan = false(length(XData),2);
% The data is cycled through to produce logical arrays for each column.
% Might be quicker to not even cycle through!!!!
for i = 1:2
TF_isnan(:,i) = isnan(CombinedArray(:,i));
end
%This is the logical array where 1's represent rows which contain bad
%data.
TF_final = logical(sum(TF_isnan,2));
% Now we select the data we like.
out_Val = YData(~TF_final,1);
out_Err = YErr(~TF_final,1);
out_X = XData(~TF_final,1);
% This is for checking what data is being selected if the user wishes
% to do so.
OutArray = horzcat(out_X,CombinedArray(~TF_final,:));
% These are the coordinates for the error region.
EFP.X = [out_X;flipud(out_X)];
EFP.Y = [out_Val+out_Err;flipud(out_Val-out_Err)];
fprintf('PatchPreProcessorFunc: Complete!\n\n');
end
function figureClosing(debugON,DataTypeList,PlotDataTypes)
for FigNum = 1:length(DataTypeList)
[~,col] = find(PlotDataTypes==FigNum);
if debugON == true && isempty(col) == false
fprintf('FigNum = %d\ncol = %d\n',FigNum,col);
end
% This happens if col is empty, which should happen if that figure
% option was not chosen, and hence it closes that figure.
if isempty(col)
close(figure(FigNum))
end
end
end