⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spm_mf_box.m

📁 toolbox for spm 5 for data, model free analysis
💻 M
📖 第 1 页 / 共 5 页
字号:
function varargout=spm_mf_box(varargin)%% mfBox - The model-free toolbox for SPM%% spm_mf_box is the main GUI window function.% Call this with SPM in the path, or directly from SPM.%% Copyright by Peter Gruber and Fabian J. Theis% Signal Processing & Information Theory group% Institute of Biophysics, University of Regensburg, Germany% Homepage: http://research.fabian.theis.name%           http://www-aglang.uni-regensburg.de%% This file is free software, subject to the % GNU GENERAL PUBLIC LICENSE, see gpl.txt% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name',mfilename, ...    'gui_Singleton',gui_Singleton, ...    'gui_OpeningFcn',@spm_mf_box_OpeningFcn, ...    'gui_OutputFcn',@spm_mf_box_OutputFcn, ...    'gui_LayoutFcn',[], ...    'gui_Callback',[]);if (nargin&&(ischar(varargin{1})))    gui_State.gui_Callback = str2func(varargin{1});endif (nargout)    [varargout{1:nargout}] = gui_mainfcn(gui_State,varargin{:});else    gui_mainfcn(gui_State,varargin{:});end% End initialization code - DO NOT EDIT% --- redraw all diagramsfunction handles=redraw_all(handles)set(handles.comp_pos,'Position',get(handles.comp_pos,'Position')); % fix for brokeness without javaset(handles.time_pos,'Position',get(handles.time_pos,'Position'));vt = floor(get(handles.time_pos,'Value'));vc = floor(get(handles.comp_pos,'Value'));set(handles.time_pos,'Value',vt)set(handles.comp_pos,'Value',vc)mt = floor(get(handles.time_pos,'Max'));mc = floor(get(handles.comp_pos,'Max'));contents = get(handles.plot_type,'String');if (isempty(contents)), t = '';else t = contents{get(handles.plot_type,'Value')};endset(handles.time,'String',sprintf('%2d/%2d',vt,mt));if (~isempty(handles.permutation)), vc = handles.permutation(vc); endif ((strcmp(t,'Post-processed Data'))&&(isfield(handles.mfbss.ppS,'tag')))    c = handles.mfbss.ppS.tag;    set(handles.comp,'String',c{vc});else    set(handles.comp,'String',sprintf('%2d/%2d',vc,mc));end[st,re] = getdisplayopts(handles.display_opts);if (isfield(handles,'lastplotstate')), oldplot = handles.lastplotstate;else oldplot = {[0,0],'none',1};endS = []; A = []; position = []; markings = {}; plotvol = {};if (strcmp(t,'Original Data'))    if (~strcmp(oldplot{2},t))        plotvol = {handles.sequence.private(vt) []};    elseif (oldplot{1}(2)~=vt)        [handles.private,position] = mfbox_databackend('getposition', ...            handles.private);        plotvol = {handles.sequence.private(vt)};    end    if (~isempty(handles.mfbss.reference))        g = mfbox_mkgrid(size(handles.mfbss.bg))';        mg = [[1;1;1],size(handles.mfbss.bg)'];        g = g(:,handles.mfbss.reference);        l = sum(handles.mfbss.reference(:));        markings{1} = {[g,mg] [ones(l,1)*0.5;0;1] [0.5,1,0.5]'};    endelseif ((strcmp(t,'Processed Data'))||(strcmp(t,'Post-processed Data'))|| ...    (strcmp(t,'Preprocessing'))||(strcmp(t,'Mask')))    plotvol = {handles.private};    if (~strcmp(oldplot{2},t))        plotvol{2} = [];        oldplot{1} = [0,0];    end    if ((strcmp(t,'Processed Data'))||(strcmp(t,'Post-processed Data')))        if (strcmp(t,'Processed Data')),            S = handles.mfbss.S.dat;            m = handles.mfbss.S.map;            mask = handles.mfbss.S.mask;        else            S = handles.mfbss.ppS.dat;            m = handles.mfbss.ppS.map;            mask = handles.mfbss.ppS.mask;        end        if (m(vt,vc)>0)            S = S(:,m(vt,vc));            sc = st*std(S(:));            if (re), S = S-mean(S(:)); end            ls = (S<-sc); us = (S>sc);            g = handles.mfbss.grid(:,mask);            mS = abs(S(:))>=(max(abs(S(:)))-eps);            maxp = g(:,mS);            if (numel(maxp))                position = maxp(:,1);            else                position = g(:,ceil(size(g,2)/2));            end            S = S(ls|us);            mg = [[1;1;1],size(handles.mfbss.bg)'];            markings{1} = {[g(:,us),mg] [S(S>0);0;1] [1,0,0]'};            markings{2} = {[g(:,ls),mg] [-S(S<0);0;1] [0,0,1]'};            if (~isempty(handles.mfbss.reference))                g = mfbox_mkgrid(size(handles.mfbss.bg))';                g = g(:,handles.mfbss.reference);                l = sum(handles.mfbss.reference(:));                markings{3} = {[g,mg] [ones(l,1)*0.5;0;1] [0.5,1,0.5]'};            end        end        if (strcmp(t,'Processed Data'))            if (size(handles.mfbss.A,2)~=0), A = handles.mfbss.A; end        else            if (size(handles.mfbss.ppA,2)~=0), A = handles.mfbss.ppA; end        end    elseif ((strcmp(t,'Preprocessing'))||(strcmp(t,'Mask')))        if (oldplot{1}(2)~=vt)            [handles.private,position] = mfbox_databackend('getposition', ...                handles.private);            if (strcmp(t,'Preprocessing'))                if (isstruct(handles.mfbss.X))                    c = reshape(mfbox_databackend('getdata', ...                        handles.mfbss.X,vt),[],1);                else                    s = size(handles.mfbss.X);                    c = reshape(handles.mfbss.X,[],s(end));                    c = c(:,vt);                end                sgr = size(handles.mfbss.grid);                sbg = size(handles.mfbss.bg);                g = mat2cell(min(repmat(sbg',1,sgr(2)), ...                    max(ones(sgr),round(handles.mfbss.grid))), ...                    ones(1,sgr(1)),sgr(2));                xm = handles.mfbss.mask(sub2ind(sbg,g{:}));                c = c(xm);                gr = handles.mfbss.grid(:,xm);                mg = [[1;1;1],sbg'];                markings{1} = {[gr(:,c>0),mg] [c(c>0);0;1] [1,0.5,0]'};                markings{2} = {[gr(:,c<0),mg] [-c(c<0);0;1] [0,0.5,1]'};            else                l = sum(handles.mfbss.mask(:));                if (l~=0)                    g = mfbox_mkgrid(size(handles.mfbss.mask))';                    mg = [[1;1;1],size(handles.mfbss.mask)'];                    markings{1} = {[g(:,handles.mfbss.mask(:)),mg] ...                        [ones(l,1)*0.75;0;1] [1,1,1]'};                end            end        end        cla(handles.timecourse); cla(handles.cross);        cla(handles.miscplot); cla(handles.histogram);    else        cla(handles.timecourse); cla(handles.cross);        cla(handles.miscplot); cla(handles.histogram);        return;    endendhandles.lastplotstate = {[vt,vc] t {st,re}};if ((~isempty(plotvol))||(~isempty(markings)))    handles.private = mfbox_databackend('redraw',handles.private, ...        plotvol,markings,position);endif (~isempty(A))    tc = A(:,vc);    ma = max(tc(:));    mi = min(tc(:));    if (~isempty(handles.mfbss.design))        ds = size(handles.mfbss.design);        colors = repmat([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1],ceil(ds(2)/6),1);        de = reshape(handles.mfbss.design*colors(1:ds(2),:),1,ds(1),3);        de = 0.5*((de-min(de(:)))/(max(de(:))-min(de(:))));        image([handles.mfbss.timeline(1),handles.mfbss.timeline(end)],[mi,ma],1-de, ...            'Parent',handles.timecourse);        set(handles.timecourse,'NextPlot','add','YDir','normal');    end    p = plot(handles.timecourse,handles.mfbss.timeline,A);    set(p,'Color',[0.7;0.7;0.7],'LineWidth',2,'LineStyle','-.');    set(handles.timecourse,'NextPlot','add');    if (isfield(handles,'mytc'))        p = plot(handles.timecourse,handles.mfbss.timeline, ...            A(:,handles.permutation(handles.mytc)));        set(p,'Color',[1;0.2;0.2],'LineWidth',2,'LineStyle','-');        set(handles.timecourse,'NextPlot','add');        handles = rmfield(handles,'mytc');    end    p = plot(handles.timecourse,handles.mfbss.timeline,real(tc));    set(p,'Color',[0;0;0],'LineWidth',3);    set(handles.timecourse,'NextPlot','replace','YLim', ...        [mi,ma]+[-1,1]*(ma-mi)/2);else    cla(handles.timecourse);endif (~isempty(S)), hist(handles.histogram,real(S),100);else cla(handles.histogram);endct = [];rel = struct();if (strcmp(t,'Processed Data'))    if (isfield(handles.mfbss,'reliability')), rel = handles.mfbss.reliability; end    if (isfield(handles.mfbss,'crosstalk')), ct = handles.mfbss.crosstalk; endelseif (strcmp(t,'Post-processed Data'))    if (isfield(handles.mfbss,'ppreliability')), rel = handles.mfbss.ppreliability; end    if (isfield(handles.mfbss,'ppcrosstalk')), ct = handles.mfbss.ppcrosstalk; endelse    cla(handles.cross); cla(handles.miscplot);    returnendif (size(ct,1)~=0)    u = triu(ct); l = tril(ct); lp = size(ct,1);    t = reshape(u(:)*[1,0,0]+l(:)*[0,0,1],[lp,lp,3])+repmat(eye(lp),[1,1,3]);    t(vc,:,2) = 0.2; t(:,vc,2) = 0.2;    image(t,'Parent',handles.cross,'ButtonDownFcn',{@cross_event_handler,handles});    set(handles.cross,'YDir','reverse')else    cla(handles.cross);endr = cell2mat(struct2cell(rel));if (size(r,1)~=0)    b = bar(handles.miscplot,r(:,vc));    set(b,'Horizontal','on','FaceColor',[0.5;0.5;0.5]);    set(handles.miscplot,'XLim',[0,1],'YTick',1:size(r,1),'YTickLabel',fieldnames(rel));else    cla(handles.miscplot);end% ---function cross_event_handler(src,eventdata,h)p = get(h.cross,'CurrentPoint'); p = p(1,1:2);h.mytc = round(p);if (~isempty(h.permutation))    h.mytc(1) = find(h.permutation==h.mytc(1));    h.mytc(2) = find(h.permutation==h.mytc(2));endif (h.mytc(1)==h.mytc(2)), set(h.comp_pos,'Value',h.mytc(1)); endh = redraw_all(h);% --- identifies button to activate, fills in appropriate drop down boxesfunction handles=reset_views(handles,varargin)nSeq = handles.sequence.timesteps;if (isstruct(handles.mfbss.X)), nX = handles.mfbss.X.timesteps;else, nX = size(handles.mfbss.X,ndims(handles.mfbss.X));end[nT,nA] = size(handles.mfbss.A);[npT,nP] = size(handles.mfbss.ppA);buttons = struct('import_data',1,'save_res',0,'load_res',1,'import_ref',0, ...    'import_des',0,'import_bg',0,'design_clear',0,'reference_clear',0, ...    'export_data',0,'export_result',0,'plot_ic_wo',0, ...    'run',0,'clear_post',0,'run_pre',0,'run_post',0,'plot',0, ...    'keeppre',0,'run_estimate',0,'load_params',1,'save_params',1, ...    'modify_params',0,'export_mask',0,'export_congraph',0, ...    'export_ics',0,'export_ic',0,'export_cross',0,'compare_ics',0, ...    'plot_connectiongraph',0);plot_types = {};display_opts = {};sort_comps = {'No sort'};keeppre = 0;if (nSeq>0)    plot_types = cat(1,plot_types,{'Original Data'});    buttons.run = 1;    buttons.run_pre = 1;    buttons.run_estimate = 1;    buttons.modify_params = 1;    buttons.import_bg = 1;    buttons.import_ref = 1;    buttons.import_des = 1;endif (nX>0)    plot_types = cat(1,plot_types,{'Mask'});    plot_types = cat(1,plot_types,{'Preprocessing'});    buttons.run_estimate = 1;    buttons.save_res = 1;    buttons.run = 1;    buttons.export_data = 1;    buttons.export_mask = 1;    buttons.modify_params = 1;    buttons.import_bg = 1;    buttons.import_ref = 1;    buttons.import_des = 1;    keeppre = 1;endif ((nX>0)&&(nSeq>0))    buttons.keeppre = 1;endif (~isempty(handles.mfbss.reference))    buttons.reference_clear = 1;endif (~isempty(handles.mfbss.design))    buttons.design_clear = 1;endif (nA>0)    plot_types = cat(1,plot_types,{'Processed Data'});    display_opts = {'>3 std, 0 centered','>2 std, 0 centered','>1 std, 0 centered', ...        '0 centered','>3 std, mean centered','>2 std, mean centered','>1 std, mean centered', ...        'mean centered'};    buttons.save_res = 1;    buttons.run_post = 1;    buttons.export_result = 1;    buttons.export_ics = 1;    buttons.export_congraph = 1;    buttons.plot = 1;    buttons.plot_ic_wo = 1;    buttons.export_ic = 1;    buttons.compare_ics = 1;    if (isfield(handles.mfbss,'extraplot'))        buttons.plot_connectiongraph = 1;    end    t = fieldnames(handles.mfbss.reliability);    for i=1:length(t), sort_comps = cat(1,sort_comps,{['Sort by ' t{i}]}); endendif (nP>0)    plot_types = cat(1,plot_types,{'Post-processed Data'});    display_opts = {'>3 std, 0 centered','>2 std, 0 centered','>1 std, 0 centered', ...        '0 centered','>3 std, mean centered','>2 std, mean centered','>1 std, mean centered', ...        'mean centered'};    buttons.clear_post = 1;endif (isempty(plot_types)), plot_types = {'No data'}; endif (isempty(display_opts)), display_opts = {'No data'}; endplot_type = length(plot_types);display_opt = 1;sort_comp = 1;for i=2:2:nargin    switch varargin{i-1}        case 'plot_type'            plot_type = min(plot_type,varargin{i});        case 'display_opt'            display_opt = varargin{i};        case 'sort_comp'            sort_comp = varargin{i};    endendswitch plot_types{plot_type}    case 'Original Data'        time_max = nSeq+0.01;        comp_max = 1.001;    case 'Mask'        time_max = 1.001;        comp_max = 1.001;    case 'Preprocessing'        time_max = nX+0.01;        comp_max = 1.001;    case 'Processed Data'        time_max = nT+0.01;        comp_max = nA+0.01;    case 'Post-processed Data'        time_max = npT+0.01;        comp_max = nP+0.01;    otherwise        time_max = 1.001;        comp_max = 1.001;endset(handles.plot_type,'Value',plot_type,'String',plot_types);set(handles.display_opts,'Value',display_opt,'String',display_opts);set(handles.sort_comp,'Value',sort_comp,'String',sort_comps);if (sort_comp==1), handles.permutation = 1:nA;else [d,handles.permutation] = sort(-handles.mfbss.reliability.(sort_comps{sort_comp}));endset(handles.time_pos,'Min',1,'Max',time_max,'Value',1, ...

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -