From 814bfc7ea4b7d7318dc4ae2928b7217edf26a9f8 Mon Sep 17 00:00:00 2001 From: Fitz Sturgill Date: Thu, 8 Feb 2018 19:34:33 -0500 Subject: [PATCH 1/2] Branch for people to test setBpodDefaultSettings function- allows you to add new settings parameters to your protocol and to recycle your old, saved protocol settings but updated to reflect the introduced settings --- .../ParameterGUI/setBpodDefaultSettings.m | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Functions/Plugins/ParameterGUI/setBpodDefaultSettings.m diff --git a/Functions/Plugins/ParameterGUI/setBpodDefaultSettings.m b/Functions/Plugins/ParameterGUI/setBpodDefaultSettings.m new file mode 100644 index 0000000..9a35575 --- /dev/null +++ b/Functions/Plugins/ParameterGUI/setBpodDefaultSettings.m @@ -0,0 +1,44 @@ +function s = setBpodDefaultSettings(s, defaults) +% FS +% allows for new settings fields to be added to protocol while still +% using old protocol settings +% +% s- settings structure +% defaults- cell array specifying settings fields and default values + +% Usage: S = BpodSystem.ProtocolSettings +% defaults = {'GUI.Epoch', 1; OdorTime, 1}; +% S = setBpodDefaultSettings(S, defaults); + + + +for counter = 1:size(defaults, 1) + sf = defaults{counter, 1}; % settings field + sv = defaults{counter, 2}; % settings value + % check to see if field exists + periods = strfind(sf, '.'); + + if isempty(periods) + lastField = sf; + firstFields = ''; + else + lastField = sf(periods(end)+1 : end); + firstFields = sf(1 : periods(end)-1); + end + + fieldSet = []; + expression = ['fieldSet=isfield(s.' firstFields ',' '''' lastField ''');']; + try + eval(expression); + catch + fieldSet = 0; + end + + % if not, then create field and assign default values + if ~fieldSet + expression = ['s.' sf '=sv;']; + eval(expression); + end +end + + \ No newline at end of file From 0827b45d0db4118f8961d2534603bffdcaf5790c Mon Sep 17 00:00:00 2001 From: Fitz Sturgill Date: Thu, 8 Feb 2018 20:03:23 -0500 Subject: [PATCH 2/2] bit better doc --- Functions/Plugins/ParameterGUI/setBpodDefaultSettings.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Functions/Plugins/ParameterGUI/setBpodDefaultSettings.m b/Functions/Plugins/ParameterGUI/setBpodDefaultSettings.m index 9a35575..db1995a 100644 --- a/Functions/Plugins/ParameterGUI/setBpodDefaultSettings.m +++ b/Functions/Plugins/ParameterGUI/setBpodDefaultSettings.m @@ -28,6 +28,9 @@ fieldSet = []; expression = ['fieldSet=isfield(s.' firstFields ',' '''' lastField ''');']; + % if the whole thing doesn't evaulate then you need to use the default value regardless, e.g. + % if GUIMeta doesn't exist at all you need to create it as well as + % associated subfields try eval(expression); catch