From dcae7c1121b9c91dc88cdf6ac751d52c31a36228 Mon Sep 17 00:00:00 2001 From: sakul-45 <81963567+sakul-45@users.noreply.github.com> Date: Fri, 9 Jul 2021 18:51:54 +0200 Subject: [PATCH] Finished function by adapting UI from correction functions --- normalize_data.m | 96 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/normalize_data.m b/normalize_data.m index 1cc466d..ddf40ae 100644 --- a/normalize_data.m +++ b/normalize_data.m @@ -1,7 +1,97 @@ -function [outputArg1,outputArg2] = normalise_data(inputArg1,inputArg2) +function [dataOUT] = normalise_data(dataIN) %NORMALISE_DATA Summary of this function goes here % Detailed explanation goes here -outputArg1 = inputArg1; -outputArg2 = inputArg2; + +%% creating UI +fig = figure; +fig.Name = 'Normalize Data'; +fig.Units = 'Normalized'; +fig.Position = [.2 .2 .6 .6]; +fig.Tag = 'Normalize'; + +%panel for plot +plotpanel = uipanel(fig); +plotpanel.Units = 'Normalized'; +plotpanel.Position = [.01 .06 .98 .92]; +%axes for plot +ax = axes(plotpanel); +ax.XLabel.String = 'Time'; +ax.YLabel.String = 'Intensity'; +%plot current data in figure with time as x axis +plot(ax,dataIN) +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 = @NormApplyButtonPushed; + +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 = @NormResetButtonPushed; + +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 = @NormDoneButtonPushed; + +%create input fields +p1 = uicontrol(fig,'Style','edit'); +p1.String = 'Left point of max region'; +p1.Units = 'Normalized'; +p1.Position = [.01 .01 .24 .05]; +p1.HorizontalAlignment = 'left'; +p1.FontUnits = 'Normalized'; +p1.FontSize = 0.6; +p1.Tag = 'MaxRegionLeft'; + +p2 = uicontrol(fig,'Style','edit'); +p2.String = 'Right point of max region'; +p2.Units = 'Normalized'; +p2.Position = [.25 .01 .24 .05]; +p2.HorizontalAlignment = 'left'; +p2.FontUnits = 'Normalized'; +p2.FontSize = 0.6; +p2.Tag = 'MaxRegionRight'; + +uicontrol(p1); %passes focus to first input +uiwait(fig) + +%% Callback functions + function NormApplyButtonPushed(src,event) + left_point = str2double(get(p1,'String')); + right_point = str2double(get(p2,'String')); + %take mean of each field line between specified min and max time + maxima_mean = mean(dataIN([left_point right_point],:)); + %normalize amplitude to 1 by dividing by max of means + dataOUT = dataIN / max(maxima_mean); + %plotting result with time as x axis + plot(ax,dataOUT) + axis tight + end + + function NormResetButtonPushed(src,event) + plot(ax,dataIN) + axis tight + end + + function NormDoneButtonPushed(src,event) + close 'Normalize Data' + end + end