-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdataSelectionCtrl.m
More file actions
151 lines (143 loc) · 6.91 KB
/
Copy pathdataSelectionCtrl.m
File metadata and controls
151 lines (143 loc) · 6.91 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
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
classdef dataSelectionCtrl < ctrlInterface
%UNTITLED2 Summary of this class goes here
% Detailed explanation goes here
properties
gui
end
methods
function obj = dataSelectionCtrl(varargin)
end
function ctrl(obj,h_panel,varargin)
% Defines a data selection interface
p = inputParser;
p.KeepUnmatched = true;
p.addParameter('fileTable',false,@islogical);
p.parse(varargin{:});
obj.guiCtrl.fileTable = p.Results.fileTable;
% Setup Layout
h.OuterBox = uix.VBox('Parent',h_panel);
h.ctrlTitle = uicontrol(h.OuterBox,'Style','text','String','Data Selection','FontSize',15);
h.dataTitle = uicontrol('Parent',h.OuterBox,'Style','text','String','Selected Data Files','FontSize',13);
h.dataBox = uix.HBox('Parent',h.OuterBox);
h.dataButtonsBox = uix.VButtonBox('Parent',h.dataBox,'VerticalAlignment','top');
h.buttonFolder = uicontrol(h.dataButtonsBox,'Style','pushbutton','String','F','Callback',@obj.loadFolder,'TooltipString','Load all MAT datafiles in a folder');
h.buttonAddData = uicontrol(h.dataButtonsBox,'Style','pushbutton','String','+','FontSize',12,'Callback',@obj.loadFile,'TooltipString','Load specific MAT datafile(s)');
h.buttonDelData = uicontrol(h.dataButtonsBox,'Style','pushbutton','String','-','FontSize',12,'Callback',@obj.removeFile,'TooltipString','Remove specific MAT datafile(s)');
h.buttonReloadData = uicontrol(h.dataButtonsBox,'Style','pushbutton','String','R','FontSize',12);
set(h.dataButtonsBox,'Spacing',5,'ButtonSize',[75 30]);
if(obj.guiCtrl.fileTable)
h.fileList = uitable(h.dataBox,'FontSize',11);
else
h.fileList = uicontrol(h.dataBox,'Style','listbox','String','Select data folder or add data files','FontSize',11,'Max',10,'Min',0);
end
set(h.dataBox,'Spacing',5,'Widths',[60 -1]);
h.emptySpace = uix.Empty('Parent',h.OuterBox);
set(h.OuterBox,'Heights',[25,25,-2,-1],'Spacing',5);
obj.guiCtrl.layout = h;
end
function loadFolder(obj,varargin)
%loadFolder Loads all the .mat files in a directory
% Loads all the .mat files in a folder
%
%
if(nargin == 3 && isa(varargin{1},'matlab.ui.control.UIControl'))
p.Results.dirName = [];
else
p = inputParser;
p.KeepUnmatched = true;
p.addOptional('dirName',[],@ischar);
p.parse(varargin{:});
end
if(isempty(p.Results.dirName))
if(isfield(obj.guiCtrl,'lastLoadFolderDir'))
startDir = obj.guiCtrl.lastLoadFolderDir;
else
startDir = pwd;
end
dirName = uigetdir(startDir,'Select the dataset directory');
if(dirName == 0)
return;
end
end
obj.guiCtrl.lastLoadFolderDir = dirName;
D = dir(dirName);
names = {D.name};
[~,~,ext] = cellfun(@fileparts,names,'UniformOutput',false);
dataPaths = cellfun(@(x) [dirName filesep x],names(strcmp(ext,'.mat')),'UniformOutput',false);
if(isfield('obj.guiCtrl','dataPaths'))
% Add to existing dataPaths
dataPaths = setdiff(dataPaths, obj.guiCtrl.dataPaths);
obj.guiCtrl.dataPaths = [obj.guiCtrl.dataPaths dataPaths];
else
obj.guiCtrl.dataPaths = dataPaths;
end
% Setup data selection display
if(~isempty(obj.guiCtrl) && ~obj.guiCtrl.fileTable && ~isempty(dataPaths))
[~, fileNames, ~] = cellfun(@fileparts,obj.guiCtrl.dataPaths,'UniformOutput',false);
obj.guiCtrl.layout.fileList.String = cellfun(@(x,y) [x ' (' y ')'],fileNames,obj.guiCtrl.dataPaths,'UniformOutput',false);
elseif(~isempty(obj.guiCtrl) && obj.guiCtrl.fileTable)
end
% obj.loadDatasets;
end
function loadFile(obj,varargin)
%loadFile Ass a .mat file
% Loads a .mat file
%
if(nargin == 3 && isa(varargin{1},'matlab.ui.control.UIControl'))
p.Results.file = [];
else
p = inputParser;
p.KeepUnmatched = true;
p.addOptional('file',[],@ischar);
p.parse(varargin{:});
end
if(isempty(p.Results.file))
if(isfield(obj.guiCtrl,'lastLoadFileDir'))
startDir = obj.guiCtrl.lastLoadFileDir;
else
startDir = pwd;
end
[fileName,pathName] = uigetfile({'*.mat','MAT-files (*.mat)'; ...
'*.*', 'All Files (*.*)'},'Select the dataset(s)',...
startDir,'MultiSelect', 'on');
if(isnumeric(fileName) && fileName == 0)
return;
end
end
obj.guiCtrl.lastLoadFileDir = pathName;
if(~iscell(fileName))
fileName = {fileName};
end
dataPaths = cellfun(@(x) fullfile(pathName, x),fileName,'UniformOutput',false);
if(isfield(obj.guiCtrl,'dataPaths'))
% Add to existing dataPaths
dataPaths = setdiff(dataPaths, obj.guiCtrl.dataPaths);
obj.guiCtrl.dataPaths = [obj.guiCtrl.dataPaths dataPaths];
else
obj.guiCtrl.dataPaths = dataPaths;
end
% Setup data selection display
if(~isempty(obj.guiCtrl) && ~obj.guiCtrl.fileTable && ~isempty(dataPaths))
[~, fileNames, ~] = cellfun(@fileparts,obj.guiCtrl.dataPaths,'UniformOutput',false);
obj.guiCtrl.layout.fileList.String = cellfun(@(x,y) [x ' (' y ')'],fileNames,obj.guiCtrl.dataPaths,'UniformOutput',false);
elseif(~isempty(obj.guiCtrl) && obj.guiCtrl.fileTable)
end
end
function removeFile(varargin)
if(nargin == 3 && isa(varargin{1},'matlab.ui.control.UIControl'))
p.Results.file = [];
else
p = inputParser;
p.KeepUnmatched = true;
p.addOptional('file',[],@ischar);
p.parse(varargin{:});
end
end
function data = loadDatasets(obj,varargin)
for dNum = 1:length(obj.datasetPaths)
data = load(obj.guiCtrl.datasetPaths{dNum});
obj.datasets(dNum) = data.MAT;
end
end
end
end