Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/canlab/CanlabCore
Browse files Browse the repository at this point in the history
  • Loading branch information
torwager committed Sep 5, 2023
2 parents a734ff8 + 2a95cb1 commit 9cdd8c3
Show file tree
Hide file tree
Showing 66 changed files with 2,530 additions and 4,633 deletions.
30 changes: 23 additions & 7 deletions CanlabCore/@atlas/select_atlas_subset.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
% 'labels_2' : If you enter any field name in the object, e.g., labels_2,
% the function will search for keyword matches here instead of in obj.labels.
%
% 'exact' : If you enter 'exact', function will not look for overlaps in
% names, and only look for exact string matches.
%
% Examples:
%
% atlasfile = which('Morel_thalamus_atlas_object.mat');
Expand Down Expand Up @@ -59,6 +62,9 @@
% Edited by tor, 12/2019, to use any field to select labels; and update
% auxiliary label fields too.
%
% Edited by Michael Sun, 09/04/2023, added an 'exact' flag, so that users
% can select to match string labels exactly and not capture regions with
% overlapping labels e.g., Cblm_Vermis_VI and Cblm_Vermis_VII.

% -------------------------------------------------------------------------
% DEFAULTS AND INPUTS
Expand All @@ -67,6 +73,7 @@
strings_to_find = [];
integers_to_find = [];
doflatten = false;
doexact=false;

% for entry of optional field to search for keywords
myfields = fieldnames(obj);
Expand All @@ -87,6 +94,7 @@
case 'flatten', doflatten = true;

% case 'xxx', xxx = varargin{i+1}; varargin{i+1} = [];
case 'exact', doexact = true;

otherwise

Expand Down Expand Up @@ -117,14 +125,22 @@
for i = 1:length(strings_to_find)

% Find which names match
wh = ~cellfun(@isempty, strfind(obj.(mylabelsfield), strings_to_find{i}));
if strmatch(mylabelsfield, 'label_descriptions')
wh=wh';
if doexact == false
wh = ~cellfun(@isempty, strfind(obj.(mylabelsfield), strings_to_find{i}));
if strmatch(mylabelsfield, 'label_descriptions')
wh=wh';
end

to_extract = to_extract | wh;
% Addition by Michael Sun 09/04/2023: Match strings exactly
else
wh = strcmp(obj.(mylabelsfield), strings_to_find{i});
if strmatch(mylabelsfield, 'label_descriptions')
wh=wh';
end

to_extract = to_extract | wh;
end


to_extract = to_extract | wh;

end

% -------------------------------------------------------------------------
Expand Down
35 changes: 33 additions & 2 deletions CanlabCore/Data_processing_tools/downsample_scnlab.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
% **new_samprate:**
% desired sampling rate in Hz
%
% **doplot:**
% visualize the plot. Default: off
%
% **method:**
% Interpolation method. Default: linear
% 'linear' (default) | 'nearest' | 'next' | 'previous' | 'pchip' |
% 'cubic' | 'v5cubic' | 'makima' | 'spline'
%
% **extrap:**
% Extrapolation strategy, specified as 'extrap' or a real scalar value.
%
% ..
% I prefer this to matlab's downsample.m because linear interpolation is
% robust and does fewer weird things to the data.
Expand All @@ -30,10 +41,30 @@
% % every 100 / TR = 100/.5 = 200 samples
%
% [yi, xi] = downsample_scnlab(y, 100, .5)
% [yi, xi] = downsample_scnlab(y, 100, .5, 'doplot', 'method', 'spline')
%
% Programmers notes:
% 8/25/2023 - Byeol
% Add more method options for interp1 function.


doplot = 0;
if length(varargin) > 0, doplot = varargin{1}; end
method = 'linear';
extrapolation = 'extrap';

for i = 1:length(varargin)
if ischar(varargin{i})
switch varargin{i}
% functional commands
case {'doplot'}
doplot = 1;
case {'method'}
method = varargin{i+1};
case {'extrap'}
extrapolation = varargin{i+1};
end
end
end

downsamplerate = orig_samprate ./ new_samprate;

Expand All @@ -49,7 +80,7 @@
xi = linspace(0, nobs, nobs_out);


yi = interp1(x, y, xi, 'linear', 'extrap');
yi = interp1(x, y, xi, method, extrapolation);

if doplot

Expand Down
63 changes: 50 additions & 13 deletions CanlabCore/HRF_Est_Toolbox2/Example2.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
if isempty(mypath), error('Cannot find directory with ilogit.m and other functions. Not on path?'); end
[mydir] = fileparts(mypath);

% load(fullfile(mydir,'timecourse'))
%
% tc = (tc- mean(tc))/std(tc);
% len = length(tc);
load(fullfile(mydir,'timecourse'))

tc = (tc- mean(tc))/std(tc);
len = length(tc);


%%
% Create HRFs

[xBF] = spm_get_bf(struct('dt', .5, 'name', 'hrf (with time and dispersion derivatives)', 'length', 32));
Expand All @@ -35,7 +37,7 @@
for i = 2:3, xx = conv(xBF.bf(:,i), [1 1]');
Xtrue1(:, i) = xx(1:66);
end
hrf1 = Xtrue * [1 .5 .3]';
hrf1 = Xtrue1 * [1 .5 .3]';


clear Xtrue2
Expand Down Expand Up @@ -312,21 +314,56 @@

figure; hold on;

plot(xsecs, beta1*hrf1, 'k', 'LineWidth', 2)
plot(xsecs, beta2*hrf2, 'k', 'LineWidth', 2)
% plot(xsecs, beta1*hrf1, 'k--', 'LineWidth', 2)
% plot(xsecs, beta2*hrf2, 'k--', 'LineWidth', 2)
%
% xsecs1 = xsecs(1:length(h1));
% han2 = plot(xsecs1, h1,'r', 'LineWidth', 2);
% xsecs2 = xsecs(1:length(h2));
% han2(3:4) = plot(xsecs2, h2,'g', 'LineWidth', 2);
% xsecs3 = xsecs(1:length(h3));
% han2(5:6) = plot(xsecs3, h3,'m', 'LineWidth', 2);
% xsecs4 = xsecs(1:length(h4));
% han2(7:8) = plot(xsecs4, h4,'b', 'LineWidth', 2);
% xsecs5 = xsecs(1:length(h5));
% han2(9:10) = plot(xsecs5, h5,'y', 'LineWidth', 2);
%
% legend(han2,{'IL1' 'IL2' 'sFIR1' 'sFIR2' 'DD1' 'DD2' 'Spline1' 'Spline2' 'NL1' 'NL2'})
% title('Estimated HRF');

subplot 121
hold
plot(xsecs, beta1*hrf1, 'k--', 'LineWidth', 2)

xsecs1 = xsecs(1:length(h1));
han2 = plot(xsecs1, h1,'r', 'LineWidth', 2);
han2 = plot(xsecs1, h1(:,1),'r', 'LineWidth', 2);
xsecs2 = xsecs(1:length(h2));
han2(3:4) = plot(xsecs2, h2,'g', 'LineWidth', 2);
han2(2) = plot(xsecs2, h2(:,1),'g', 'LineWidth', 2);
xsecs3 = xsecs(1:length(h3));
han2(5:6) = plot(xsecs3, h3,'m', 'LineWidth', 2);
han2(3) = plot(xsecs3, h3(:,1),'m', 'LineWidth', 2);
xsecs4 = xsecs(1:length(h4));
han2(7:8) = plot(xsecs4, h4,'b', 'LineWidth', 2);
han2(4) = plot(xsecs4, h4(:,1),'b', 'LineWidth', 2);
xsecs5 = xsecs(1:length(h5));
han2(9:10) = plot(xsecs5, h5,'y', 'LineWidth', 2);
han2(5) = plot(xsecs5, h5(:,1),'y', 'LineWidth', 2);

legend(han2,{'IL1' 'IL2' 'sFIR1' 'sFIR2' 'DD1' 'DD2' 'Spline1' 'Spline2' 'NL1' 'NL2'})
legend(han2,{'IL1' 'sFIR1' 'DD1' 'Spline1' 'NL1'})
title('Estimated HRF');

subplot 122
hold
plot(xsecs, beta2*hrf2, 'k--', 'LineWidth', 2)

xsecs1 = xsecs(1:length(h1));
han2 = plot(xsecs1, h1(:,2),'r', 'LineWidth', 2);
xsecs2 = xsecs(1:length(h2));
han2(2) = plot(xsecs2, h2(:,2),'g', 'LineWidth', 2);
xsecs3 = xsecs(1:length(h3));
han2(3) = plot(xsecs3, h3(:,2),'m', 'LineWidth', 2);
xsecs4 = xsecs(1:length(h4));
han2(4) = plot(xsecs4, h4(:,2),'b', 'LineWidth', 2);
xsecs5 = xsecs(1:length(h5));
han2(5) = plot(xsecs5, h5(:,2),'y', 'LineWidth', 2);

legend(han2,{'IL2' 'sFIR2' 'DD2' 'Spline2' 'NL2'})
title('Estimated HRF');

Loading

0 comments on commit 9cdd8c3

Please sign in to comment.