Finished UI based correction, including reset button.
This commit is contained in:
parent
4520e1e1d4
commit
f660db6d96
@ -1,42 +1,97 @@
|
||||
function [dataOUT] = correct_time_baseline(dataIN)
|
||||
%CORRECT_TIME_BASELINE Summary of this function goes here
|
||||
% Detailed explanation goes here
|
||||
%CORRECT_TIME_BASELINE UI for basline correction along time axis
|
||||
%
|
||||
% Usage: [dataOUT] = CORRECT_TIME_BASELINE(dataIN), where dataIN is a
|
||||
% dataset loaded via the LOAD_MATLAB or LOAD_BRUKER function.
|
||||
%
|
||||
% The function will show the raw data and offer an input field, where the
|
||||
% number of pretrigger points should be set. By pressing "Apply" the
|
||||
% correction will be executed and the graph changes to the corrected data.
|
||||
% By pressing "Reset" the graph will return to show the original data.
|
||||
% Exit the function by pressing "Done".
|
||||
|
||||
%Create figure
|
||||
f = figure('Units','Normalized',...
|
||||
'Position',[.3 .3 .4 .4],...
|
||||
'NumberTitle','off',...
|
||||
'Name','Choose Pretrigger');
|
||||
%input field
|
||||
inp = uicontrol('Style','Edit',...
|
||||
'Units','Normalized',...
|
||||
'Position',[.025 .025 .7 .05],...
|
||||
'Tag','myedit');
|
||||
%"Done" button
|
||||
p = uicontrol('Style','PushButton',...
|
||||
'Units','Normalized',...
|
||||
'Position',[.75 .025 .225 .05],...
|
||||
'String','Done',...
|
||||
'CallBack','uiresume(gcbf)');
|
||||
%% creating UI
|
||||
fig = figure;
|
||||
fig.Name = 'Correct Time Baseline';
|
||||
fig.Units = 'Normalized';
|
||||
fig.Position = [.2 .2 .6 .6];
|
||||
fig.Tag = 'CorrTimeBase';
|
||||
|
||||
%panel for plot
|
||||
plotpanel = uipanel(fig);
|
||||
plotpanel.Units = 'Normalized';
|
||||
plotpanel.Position = [.01 .06 .98 .92];
|
||||
%axes for plot
|
||||
ax = axes(f,'Units','Normalized',...
|
||||
'Position',[.05 .125 .925 .85]);
|
||||
ax = axes(plotpanel);
|
||||
ax.XLabel.String = 'Time';
|
||||
ax.YLabel.String = 'Intensity';
|
||||
%plot current data in figure
|
||||
plot(ax,dataIN)
|
||||
axis tight
|
||||
%wait until button pressed
|
||||
uiwait(f)
|
||||
pretrigger = str2double(get(inp,'String'));
|
||||
|
||||
%timeline CORRECTING
|
||||
data_size = size(dataIN);
|
||||
dataOUT = zeros(data_size);
|
||||
for n = 1:data_size(2)
|
||||
column_mean = mean(dataIN(1:pretrigger,n));
|
||||
dataOUT(:,n) = dataIN(:,n) - column_mean;
|
||||
end
|
||||
%plotting result
|
||||
plot(ax,dataOUT)
|
||||
axis tight
|
||||
%create push buttons
|
||||
a = uicontrol(fig,'Style','pushbutton');
|
||||
a.String = 'Apply';
|
||||
a.Units = 'Normalized';
|
||||
a.Position = [.52 .01 .15 .05];
|
||||
a.FontUnits = 'Normalized';
|
||||
a.FontSize = 0.6;
|
||||
a.Tag = 'Apply';
|
||||
a.Callback = @ApplyButtonPushed;
|
||||
|
||||
r = uicontrol(fig,'Style','pushbutton');
|
||||
r.String = 'Reset';
|
||||
r.Units = 'Normalized';
|
||||
r.Position = [.68 .01 .15 .05];
|
||||
r.FontUnits = 'Normalized';
|
||||
r.FontSize = 0.6;
|
||||
r.Tag = 'Reset';
|
||||
r.Callback = @ResetButtonPushed;
|
||||
|
||||
d = uicontrol(fig,'Style','pushbutton');
|
||||
d.String = 'Done';
|
||||
d.Units = 'Normalized';
|
||||
d.Position = [.84 .01 .15 .05];
|
||||
d.FontUnits = 'Normalized';
|
||||
d.FontSize = 0.6;
|
||||
d.Tag = 'Done';
|
||||
d.Callback = @DoneButtonPushed;
|
||||
|
||||
%create input field
|
||||
inp = uicontrol(fig,'Style','edit');
|
||||
inp.Units = 'Normalized';
|
||||
inp.Position = [.01 .01 .5 .05];
|
||||
inp.HorizontalAlignment = 'left';
|
||||
inp.FontUnits = 'Normalized';
|
||||
inp.FontSize = 0.6;
|
||||
inp.Tag = 'TimePoints';
|
||||
|
||||
uicontrol(inp); %passes focus to input
|
||||
uiwait(fig)
|
||||
|
||||
%% Callback functions
|
||||
function ApplyButtonPushed(src,event)
|
||||
pretrigger = str2double(get(inp,'String'));
|
||||
%timeline CORRECTING
|
||||
data_size = size(dataIN);
|
||||
dataOUT = zeros(data_size);
|
||||
for n = 1:data_size(2)
|
||||
column_mean = mean(dataIN(1:pretrigger,n));
|
||||
dataOUT(:,n) = dataIN(:,n) - column_mean;
|
||||
end
|
||||
%plotting result
|
||||
plot(ax,dataOUT)
|
||||
axis tight
|
||||
end
|
||||
|
||||
function ResetButtonPushed(src,event)
|
||||
plot(ax,dataIN)
|
||||
axis tight
|
||||
end
|
||||
|
||||
function DoneButtonPushed(src,event)
|
||||
close 'Correct Time Baseline'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user