-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsolidation_GUI.m
More file actions
144 lines (126 loc) · 5.85 KB
/
consolidation_GUI.m
File metadata and controls
144 lines (126 loc) · 5.85 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
function physioRDecoGUI()
% Create the main figure window
fig = uifigure('Name', 'Physio and R-Deco File Combiner', ...
'Position', [100 100 400 300], ...
'Resize', 'off');
% Create labels and buttons for file selection
uilabel(fig, 'Position', [20 250 150 20], 'Text', 'Select Physio File:');
physioButton = uibutton(fig, 'push', ...
'Position', [180 250 200 22], ...
'Text', 'Browse...', ...
'ButtonPushedFcn', @(btn, event) selectPhysioFile(btn, fig));
uilabel(fig, 'Position', [20 200 150 20], 'Text', 'Select R-Deco File:');
rDecoButton = uibutton(fig, 'push', ...
'Position', [180 200 200 22], ...
'Text', 'Browse...', ...
'ButtonPushedFcn', @(btn, event) selectRDecoFile(btn, fig));
uilabel(fig, 'Position', [20 150 150 20], 'Text', 'Select Output File:');
outputButton = uibutton(fig, 'push', ...
'Position', [180 150 200 22], ...
'Text', 'Browse...', ...
'ButtonPushedFcn', @(btn, event) selectOutputFile(btn, fig));
% Create Process button
processButton = uibutton(fig, 'push', ...
'Position', [150 50 100 22], ...
'Text', 'Process', ...
'ButtonPushedFcn', @(btn, event) processFiles(btn, fig));
% Store file paths in the figure's UserData
fig.UserData = struct('physioPath', '', 'rDecoPath', '', 'outputPath', '');
% Function to select physio file
function selectPhysioFile(~, ~)
[file, path] = uigetfile('*.mat', 'Select Physio File');
if isequal(file, 0)
return; % User canceled
end
fullPath = fullfile(path, file);
fig.UserData.physioPath = fullPath;
physioButton.Text = ['Physio: ' file];
end
% Function to select R-Deco file
function selectRDecoFile(~, ~)
[file, path] = uigetfile('*.mat', 'Select R-Deco File');
if isequal(file, 0)
return; % User canceled
end
fullPath = fullfile(path, file);
fig.UserData.rDecoPath = fullPath;
rDecoButton.Text = ['R-Deco: ' file];
end
% Function to select output file
function selectOutputFile(~, ~)
[file, path] = uiputfile('*.mat', 'Save Annotated Physio File As');
if isequal(file, 0)
return; % User canceled
end
fullPath = fullfile(path, file);
fig.UserData.outputPath = fullPath;
outputButton.Text = ['Output: ' file];
end
% Function to process files
function processFiles(~, ~)
physioPath = fig.UserData.physioPath;
rDecoPath = fig.UserData.rDecoPath;
outputPath = fig.UserData.outputPath;
% Check if all paths are provided
if isempty(physioPath) || isempty(rDecoPath) || isempty(outputPath)
uialert(fig, 'Please select all files before processing.', 'Error');
return;
end
% Check if files exist
if ~exist(physioPath, 'file') || ~exist(rDecoPath, 'file')
uialert(fig, 'One or more input files do not exist. Please check the paths.', 'Error');
return;
end
try
% Load the preprocessed physio data into a structure to avoid workspace conflicts
physioData = load(physioPath);
rDecoData = load(rDecoPath);
% Extract variables from physioData (ensure they exist)
requiredVars = {'RESP', 'RPIEZO', 'MRTRIG', 'STIMTRIG', 'name', 'PIEZOF', 'PIEZOD'};
for var = requiredVars
if ~isfield(physioData, var{1})
error(['Missing required variable in physio file: ' var{1}]);
end
end
% Assign variables locally
RESP = physioData.RESP;
RPIEZO = physioData.RPIEZO;
MRTRIG = physioData.MRTRIG;
STIMTRIG = physioData.STIMTRIG;
name = physioData.name;
PIEZOF = physioData.PIEZOF;
PIEZOD = physioData.PIEZOD;
% Extract R-peak data from R-Deco
if ~isfield(rDecoData.data, 'R_loc')
error('R-peak data (R_loc) not found in R-Deco file.');
end
t = rDecoData.data.R_loc; t = t{1,1};
r = ones(1, length(t));
for j = 1:length(t)
[Y, M, D, H, MN, S] = datevec(t(j));
r(j) = H*3600 + MN*60 + S;
end
% Create a new physio struct to store all data
physio = struct();
physio.RESP = RESP;
physio.RPIEZO = RPIEZO;
physio.MRTRIG = MRTRIG;
physio.STIMTRIG = STIMTRIG;
physio.PIEZOF = PIEZOF;
physio.PIEZOD = PIEZOD;
physio.name = name;
physio.piezoout = r; % Add R-peak annotations (no task-specific field)
% Save the combined data to the specified output file
save(outputPath, 'physio');
% Create a simple green checkmark icon (16x16 pixels for msgbox)
greenIcon = zeros(16, 16, 3, 'uint8'); % RGB image
greenIcon(:,:,2) = 255; % Set green channel to max (pure green)
greenIcon(6:11, 3:8, :) = 0; % Black checkmark-like shape (simplified)
greenIcon(6:11, 9:14, :) = 0; % Second part of checkmark
% Display the message box
msgbox(['Awesome! Your annotated physio data is saved to: ' outputPath], 'Success', 'custom', greenIcon);
catch ME
uialert(fig, ['Error processing files: ' ME.message], 'Error');
end
end
end