diff --git a/src/pspm_rev_dcm.m b/src/pspm_rev_dcm.m index 59cc19ec..376f18b3 100644 --- a/src/pspm_rev_dcm.m +++ b/src/pspm_rev_dcm.m @@ -19,12 +19,16 @@ % 'scrf' show peripheral skin conductance response function as used % for trial-by-trial estimation of sympathetic input % 'names' show trial and condition names in command window +% 'seg' show the mean responses of all segments identified in +% the DCM model. ('pspm_extract_segments') % * sn: session. % * trl: trial. % ● History % Introduced In PsPM 3.0 % Written in 2008-2015 by Dominik R Bach (Wellcome Trust Centre for Neuroimaging) % Maintained in 2022 by Teddy +% Maintained in 2024 by Bernhard Agoué von Raußendorf + %% Initialise global settings @@ -123,6 +127,47 @@ fprintf('Condition %d: %s\n',n,dcm.condnames{n}); end; fprintf('---------------------------------------\n'); + case 'seg' + + options = struct(); + [ssts, segments] = pspm_extract_segments('model', dcm, options); + + if ssts == -1 + uiwait(msgbox('Error extracting segments from the model.', 'Error')) + else + + + sr = dcm.input.sr; + cmap = lines(numel(segments.segments)); + f.h = figure; + f.a.h = axes(f.h); + hold on; + + legendNames = cell(1, numel(segments.segments)); + + for x = 1:numel(segments.segments) + + plotdata = segments.segments{x}.mean; + t = (1:length(plotdata)) / sr; + f.a.p = plot(f.a.h, t, plotdata, 'Color', cmap(x, :), 'LineWidth', 1); + legendNames{x} = segments.segments{x}.name; + + end + + f.a.l = legend(legendNames, 'Interpreter', 'none', 'Location', 'best'); + legend boxoff + + set(get(f.a.h, 'xlabel'), 'String', 'Time (seconds)'); + set(get(f.a.h, 'ylabel'), 'String', 'Mean Response (data units)'); + set(get(f.a.h, 'title'), 'String', 'Mean Responses for All Segments'); + + hold off; + end + + + + + end; sts = 1; diff --git a/src/pspm_rev_glm.m b/src/pspm_rev_glm.m index 73f508a0..36b8e1f2 100644 --- a/src/pspm_rev_glm.m +++ b/src/pspm_rev_glm.m @@ -13,6 +13,7 @@ % 3 - predicted & observed % 4 - print regressor names % 5 - reconstructed responses +% 6 - plot mean responses of all segments % ● Outputs % * sts : status variable indicating whether the function run successfully % * fig : returns the figure handles @@ -20,6 +21,7 @@ % Introduced In PsPM 3.0 % Written in 2008-2015 by Dominik R Bach (Wellcome Trust Centre for Neuroimaging) % Maintained in 2022 by Teddy +% Maintained in 2024 by Bernhard Agoué von Raußendorf % initialise global settings @@ -226,6 +228,41 @@ XLim = cellfun(@(x){num2str(x)}, XLim); set(fig(5).ax(1).h, 'XTickLabel',XLim); set(fig(5).title, 'String', sprintf('Estimated responses per condition: %s', filename), 'FontWeight', 'Bold', 'FontSize', 14, 'Interpreter', 'none'); + case 6 + + options = struct(); + [ssts, segments] = pspm_extract_segments('model', glm, options); + if ssts == -1 + uiwait(msgbox('Error extracting segments from the model.', 'Error')) + else + sr = glm.input.sr; + cmap = lines(numel(segments.segments)); + f.h = figure; + f.a.h = axes(f.h); + hold on; + + legendNames = cell(1, numel(segments.segments)); + + for x = 1:numel(segments.segments) + + plotdata = segments.segments{x}.mean; + t = (1:length(plotdata)) / sr; + f.a.p = plot(f.a.h, t, plotdata, 'Color', cmap(x, :), 'LineWidth', 1); + legendNames{x} = segments.segments{x}.name; + + end + + f.a.l = legend(legendNames, 'Interpreter', 'none', 'Location', 'best'); + legend boxoff + + set(get(f.a.h, 'xlabel'), 'String', 'Time (seconds)'); + set(get(f.a.h, 'ylabel'), 'String', 'Mean Response (data units)'); + set(get(f.a.h, 'title'), 'String', 'Mean Responses for All Segments'); + + hold off; + end + + end end diff --git a/src/pspm_review.fig b/src/pspm_review.fig index 28b0ec60..c5e45071 100644 Binary files a/src/pspm_review.fig and b/src/pspm_review.fig differ diff --git a/src/pspm_review.m b/src/pspm_review.m index a133eb43..53b71562 100644 --- a/src/pspm_review.m +++ b/src/pspm_review.m @@ -137,14 +137,14 @@ function buttonAddModel_Callback(hObject, ~, handles) end setButtonEnable(handles) -if handles.modelCnt > 1 - set(handles.buttonRemoveModel2, 'Enable', 'on'); +if handles.modelCnt > 1 + set(handles.buttonRemoveModel, 'Enable', 'on'); end guidata(hObject, handles); -% --- Executes on button press in buttonRemoveModel2. +% --- Executes on button press in buttonRemoveModel. function buttonRemoveModel_Callback(hObject, ~, handles) -% hObject handle to buttonRemoveModel2 (see GCBO) +% hObject handle to buttonRemoveModel (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) handles.modelData{handles.currentModel} = []; @@ -157,8 +157,8 @@ function buttonRemoveModel_Callback(hObject, ~, handles) handles.currentModel = handles.modelCnt; end set(handles.listModel, 'Value', handles.currentModel); -if handles.modelCnt < 2 - set(handles.buttonRemoveModel2, 'Enable', 'off'); +if handles.modelCnt < 2 + set(handles.buttonRemoveModel, 'Enable', 'off'); end showModel(handles); @@ -201,7 +201,7 @@ function buttonPlot1_Callback(hObject, ~, handles) case 'dcm' sessionNr = checkSessionNr(handles); if sessionNr - pspm_rev_dcm(handles.modelData{handles.currentModel}.model, 'sum', sessionNr, []) + pspm_rev_dcm(handles.modelData{handles.currentModel}.model, 'sum', sessionNr, []); end case 'sf' @@ -294,12 +294,13 @@ function buttonPlot5_Callback(hObject, ~, handles) tmpStatusString = get(handles.textStatus,'String'); set(handles.textStatus,'String','Plotting is in progress. Please wait...'); switch handles.modelData{handles.currentModel}.modeltype + case 'glm' [~, handles.modelData{handles.currentModel}.fig] = ... pspm_rev_glm(handles.modelData{handles.currentModel}.modelfile, 5); + case 'dcm' - [~, handles.modelData{handles.currentModel}.fig] = ... - pspm_rev_con(handles.modelData{handles.currentModel}.model); + pspm_rev_dcm(handles.modelData{handles.currentModel}.modelfile, 'seg', [], []); end set(handles.textStatus,'String',tmpStatusString); @@ -315,44 +316,14 @@ function buttonPlot6_Callback(hObject, ~, handles) set(handles.textStatus,'String','Plotting is in progress. Please wait...'); switch handles.modelData{handles.currentModel}.modeltype case 'glm' - - modelfile = handles.modelData{handles.currentModel}.modelfile; - options = struct(); - [ssts, segments] = pspm_extract_segments('model', modelfile, options); - - if ssts == -1 - uiwait(msgbox('Error extracting segments from the model.', 'Error')) - else - - glm = handles.modelData{handles.currentModel}.model; - sr = glm.input.sr; - cmap = lines(numel(segments.segments)); - f.h = figure; - f.a.h = axes(f.h); - hold on; - - legendNames = cell(1, numel(segments.segments)); - - for x = 1:numel(segments.segments) - - plotdata = segments.segments{x}.mean; - t = (1:length(plotdata)) / sr; - f.a.p = plot(f.a.h, t, plotdata, 'Color', cmap(x, :), 'LineWidth', 1); - legendNames{x} = segments.segments{x}.name; - - end - - f.a.l = legend(legendNames, 'Interpreter', 'none', 'Location', 'best'); - legend boxoff - - set(get(f.a.h, 'xlabel'), 'String', 'Time (seconds)'); - set(get(f.a.h, 'ylabel'), 'String', 'Mean Response (data units)'); - set(get(f.a.h, 'title'), 'String', 'Mean Responses for All Segments'); - - hold off; - end + modelfile = handles.modelData{handles.currentModel}.modelfile; + [~, handles.modelData{handles.currentModel}.fig] = pspm_rev_glm(modelfile, 6); + % contrast in comand window + case 'dcm' + [~, handles.modelData{handles.currentModel}.fig] = ... + pspm_rev_con(handles.modelData{handles.currentModel}.model); end @@ -543,15 +514,17 @@ function showModel(handles) buttonPlotString = {'Display', ... 'Display', ... 'Display', ... - 'Show'}; + 'Show', ... + 'Plot'}; textPlotString = {'All trials for one session', ... 'Diagnostics for trial nr.', ... 'Skin conductance response function (SCR)', ... - 'Trial and condition names in command window'}; + 'Trial and condition names in command window', ... + 'Plot data per condition'}; % detect contrasts if isfield(handles.modelData{handles.currentModel}.model, 'con') - buttonPlotString{5} = 'Show'; - textPlotString{5} = 'Contrast names in command window'; + buttonPlotString{6} = 'Show'; + textPlotString{6} = 'Contrast names in command window'; end setInvisble(handles); setButtonPlotString(handles, buttonPlotString);