Finished objectifying #8
| @ -1,42 +1,97 @@ | |||||||
| function [dataOUT] = correct_time_baseline(dataIN) | function [dataOUT] = correct_time_baseline(dataIN) | ||||||
| %CORRECT_TIME_BASELINE Summary of this function goes here | %CORRECT_TIME_BASELINE UI for basline correction along time axis | ||||||
| %   Detailed explanation goes here | % | ||||||
|  | %   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 | %% creating UI | ||||||
| f = figure('Units','Normalized',... | fig = figure; | ||||||
|      'Position',[.3 .3 .4 .4],... | fig.Name = 'Correct Time Baseline'; | ||||||
|      'NumberTitle','off',... | fig.Units = 'Normalized'; | ||||||
|      'Name','Choose Pretrigger'); | fig.Position = [.2 .2 .6 .6]; | ||||||
| %input field | fig.Tag = 'CorrTimeBase'; | ||||||
| inp = uicontrol('Style','Edit',... | 
 | ||||||
|      'Units','Normalized',... | %panel for plot | ||||||
|      'Position',[.025 .025 .7 .05],... | plotpanel = uipanel(fig); | ||||||
|      'Tag','myedit'); | plotpanel.Units = 'Normalized'; | ||||||
| %"Done" button | plotpanel.Position = [.01 .06 .98 .92]; | ||||||
| p = uicontrol('Style','PushButton',... |  | ||||||
|      'Units','Normalized',... |  | ||||||
|      'Position',[.75 .025 .225 .05],... |  | ||||||
|      'String','Done',... |  | ||||||
|      'CallBack','uiresume(gcbf)'); |  | ||||||
| %axes for plot | %axes for plot | ||||||
| ax = axes(f,'Units','Normalized',... | ax = axes(plotpanel); | ||||||
|      'Position',[.05 .125 .925 .85]); | ax.XLabel.String = 'Time'; | ||||||
|  | ax.YLabel.String = 'Intensity'; | ||||||
| %plot current data in figure | %plot current data in figure | ||||||
| plot(ax,dataIN) | plot(ax,dataIN) | ||||||
| axis tight | axis tight | ||||||
| %wait until button pressed |  | ||||||
| uiwait(f) |  | ||||||
| pretrigger = str2double(get(inp,'String')); |  | ||||||
| 
 | 
 | ||||||
| %timeline CORRECTING | %create push buttons | ||||||
| data_size = size(dataIN); | a = uicontrol(fig,'Style','pushbutton'); | ||||||
| dataOUT = zeros(data_size); | a.String = 'Apply'; | ||||||
| for n = 1:data_size(2) | a.Units = 'Normalized'; | ||||||
|     column_mean = mean(dataIN(1:pretrigger,n)); | a.Position = [.52 .01 .15 .05]; | ||||||
|     dataOUT(:,n) = dataIN(:,n) - column_mean; | a.FontUnits = 'Normalized'; | ||||||
| end | a.FontSize = 0.6; | ||||||
| %plotting result | a.Tag = 'Apply'; | ||||||
| plot(ax,dataOUT) | a.Callback = @ApplyButtonPushed; | ||||||
| axis tight | 
 | ||||||
|  | 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 | end | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user