-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreProcessInputSignals.m
100 lines (93 loc) · 3.6 KB
/
PreProcessInputSignals.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
%% Pre-process Input Signals
%
% This script pre-processes input signals which will be subsequently used
% for to generate a characteristic average and response corridors.
% Preprocessing amalgoamtes several curves, ensures the validity of said
% curves, and saves the data into a single MATLAB data file for later use.
%
% This script is provided as part of ARCGen, which is released under a GNU
% GPL v3 license. No warranty or support is provided. The authors any
% responsibility for the validity, accuracy, or applicability of any
% results obtained from this code.
%
% Input signals must be saved in individual CSV files, with data saved in
% columns. The user can set which two column indices are used as the input
% x and y data.
%
% Corridor generation is performed in a separate script
%
% Corridor generation scripts requires that input data be organized using a
% structure array. The structure array must have two entries per response
% curve
% + data: [n,2] array of x-y data
% + specId: A character string used as a specimen identifier.
%
% This script has four options to specify "specId" in a programatic
% fashion. This is defined using "flagAlterSpecID".
% + "No": "specId" is taken directly from the file name of the .csv
% + "RemoveUnderscore": "specId" is the file name of the .csv with
% underscores replaced with spaces
% + "Squential": "specId" is defined sequential with "sequentialBase"
% used as a prefix
% + "Manual": "specId" is defined using the cell array "manualSpecIds".
% "manualSpecId" must be the same length as .csv file being
% processed.
%
% Copyright (c) 2022 Devon C. Hartlen
%% Initialization
fclose all;
close all;
clear;
clc;
addpath('ThirdPartyFunctions') % Path to 3rd party functions
%% Select desired data files to be processed
% This is accomplished with a UI
inputFilenames = uipickfiles('Output','struct');
% correct file names
for iFile = 1:length(inputFilenames)
[~,name,ext] = fileparts(inputFilenames(iFile).name);
inputFilenames(iFile).specId = name;
end
%% Alter specimen ID from file name (if desired)
% Cases: 'No','RemoveUnderscore','Sequential','Manual'
flagAlterSpecID = 'RemoveUnderscore';
sequentialBase = 'ID';
manualSpecIds = {...
'ID1';...
'ID2';...
};
switch flagAlterSpecID
case 'No'
disp('Skipping rename')
case 'RemoveUnderscore'
for iFile = 1:length(inputFilenames)
inputFilenames(iFile).specId = ...
replace(inputFilenames(iFile).specId,'_(x)','');
inputFilenames(iFile).specId = ...
replace(inputFilenames(iFile).specId,'_',' ');
end
case 'Sequential'
for iFile = 1:length(inputFilenames)
inputFilenames(iFile).specId = ...
[sequentialBase ' ' num2str(iFile,'%3d')];
end
case 'Manual'
if length(manualSpecIds) ~= length(inputFilenames)
error('Not enough manual IDs specified')
else
for iFile = 1:length(inputFilenames)
inputFilenames(iFile).specId = manualSpecIds{iFile};
end
end
end
%% Load response curves
% Specify x,y columns of datafile to be loaded
indicesCurves = [1,2];
inputSignals = struct([]); % initialization
for iFile = 1:length(inputFilenames)
curveData = readmatrix(inputFilenames(iFile).name); % R2020a required
inputSignals(iFile).specId = inputFilenames(iFile).specId;
inputSignals(iFile).data = curveData(:,indicesCurves);
end
%% Save response curves to file
uisave({'inputSignals'})