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

📄 spm_mf_box.m

📁 toolbox for spm 5 for data, model free analysis
💻 M
📖 第 1 页 / 共 5 页
字号:
    handles.params_filename);for i=1:length(p)    if (isfield(mfbss,p{i})), handles.mfbss.(p{i}) = mfbss.(p{i}); endendif (nSeq>0)    for i=1:length(pp)        if (isfield(mfbss,pp{i})), handles.mfbss.(pp{i}) = mfbss.(pp{i}); end    end    handles.mfbss.X = [];endc = get(handles.mf_algo,'String');v = find(strcmp(c,handles.mfbss.name));if (length(v)==1), set(handles.mf_algo,'Value',v); endc = get(handles.algo_reliability,'String');v = find(strcmp(c,handles.mfbss.rel_name));if (length(v)==1), set(handles.algo_reliability,'Value',v); endc = get(handles.algo_preprocess,'String');p = false(1,length(c));for i=1:length(handles.mfbss.pre_name)    % find the names of the selected preprocessing algorithms    p = p | strcmp(c,handles.mfbss.pre_name{i})';endset(handles.algo_preprocess,'Value',find(p));c = get(handles.algo_postprocess,'String');if isempty(handles.mfbss.pos_name)==false    v = find(strcmp(c,handles.mfbss.pos_name));    if (length(v)==1), set(handles.algo_postprocess,'Value',v); endendhandles = reset_views(handles);guidata(hObject,handles);% --- Executes on button press in save_params.function save_params_Callback(hObject,eventdata,handles)p = {'name','params','pre_name','pre_params','rel_name', ...    'rel_params','pos_name','pos_params'};mfbss = struct();for i=1:length(p), mfbss.(p{i}) = handles.mfbss.(p{i}); endcontents = get(handles.mf_algo,'String');mfbss.name = contents{get(handles.mf_algo,'Value')};contents = get(handles.algo_preprocess,'String');mfbss.pre_name = {contents{get(handles.algo_preprocess,'Value')}};contents = get(handles.algo_reliability,'String');mfbss.rel_name = contents{get(handles.algo_reliability,'Value')};mfbox_databackend('save_params',mfbss,handles.params_filename);guidata(hObject,handles);% --- Executes on button press in modify_params.function modify_params_Callback(hObject,eventdata,handles)contents = get(handles.algo_preprocess,'String');cmd_pre = {contents{get(handles.algo_preprocess,'Value')}};contents = get(handles.mf_algo,'String');cmd_algo = contents{get(handles.mf_algo,'Value')};contents = get(handles.algo_reliability,'String');cmd_rel = contents{get(handles.algo_reliability,'Value')};if (handles.sequence.timesteps>0)    dim = handles.sequence.dim;    ts = handles.sequence.timesteps;    mfbss = struct('X',handles.sequence, ...        'dim',dim,'mask',true(dim), ...        'grid',reshape(mfbox_mkgrid(dim)',[length(dim),dim]));    for i=1:length(cmd_pre)        cmd = cmd_pre{i};        p = {};        if (isfield(handles.mfbss.pre_params,cmd))            p = handles.mfbss.pre_params.(cmd);        end        cmd_func = str2func(sprintf('mfbox_pre_%s_run',cmd));        [d,m,g,t,handles.mfbss.pre_params.(cmd)] = cmd_func(mfbss.X, ...            mfbss.mask,mfbss.grid,handles.mfbss.timeline,p,0,handles.private);    endelse    dim = size(handles.mfbss.mask);    sd = size(handles.mfbss.X);    ts = sd(end);    mfbss = handles.mfbss;endp = {};if (isfield(handles.mfbss.params,cmd_algo))    p = handles.mfbss.params.(cmd_algo);endcmd_func = str2func(sprintf('mfbox_%s_run',cmd_algo));[handles.mfbss.params.(cmd_algo)] = cmd_func(zeros(1,ts),mfbss.mask,p,0);p = {};if (isfield(handles.mfbss.params,cmd_rel))    p = handles.mfbss.rel_params.(cmd_rel);endcmd_func = str2func(sprintf('mfbox_rel_%s_run',cmd_rel));[mfbss,handles.mfbss.rel_params.(cmd_rel)] = cmd_func(mfbss,p,0);guidata(hObject,handles);% --- Executes on button press in design_clear.function design_clear_Callback(hObject, eventdata, handles)handles.mfbss.design = [];if (~isempty(handles.mfbss.A))    handles.mfbss.reliability = updatedesign(handles.mfbss.reliability, ...        handles.mfbss.design,handles.mfbss.timeline,handles.mfbss.A);else    if (isfield(handles.mfbss.reliability,'design'))        handles.mfbss.reliability = rmfield(handles.mfbss.reliability,'design');    endendhandles = reset_views(handles);guidata(hObject,handles);% --- Executes on button press in reference_clear.function reference_clear_Callback(hObject, eventdata, handles)handles.mfbss.reference = [];if ((isfield(handles.mfbss.S,'dat'))&&(~isempty(handles.mfbss.reference)))    s = [size(handles.mfbss.S.dat,1),size(handles.mfbss.S.map,2)];    S = zeros(s);    for i=1:s(2)        j = unique(handles.mfbss.S.map(:,i));        S(:,i) = sum(handles.mfbss.S.dat(:,j),2)/length(j);    end    handles.mfbss.reliability = updatereference(handles.mfbss.reliability, ...        handles.mfbss.reference,S,handles.mfbss.grid(:,handles.mfbss.S.mask));else    if (isfield(handles.mfbss.reliability,'reference'))        handles.mfbss.reliability = rmfield(handles.mfbss.reliability,'reference');    endendhandles = reset_views(handles);guidata(hObject,handles);% --- Executes on button press in export_cross.function export_cross_Callback(hObject,eventdata,handles)contents = get(handles.plot_type,'String');if (isempty(contents)), t = '';else t = contents{get(handles.plot_type,'Value')};endC = [];if (strcmp(t,'Processed Data'))    C = handles.mfbss.crosstalk;elseif (strcmp(t,'Post-processed Data'))    C = handles.mfbss.ppcrosstalk;endif (~isempty(C))    [f,d] = uiputfile('*.mat','Select output file ...');    tmpfile = fullfile(d,f);    save(tmpfile,'C','-v6');end% --- Executes on button press in export_congraph.function export_congraph_Callback(hObject,eventdata,handles)contents = get(handles.plot_type,'String');if (isempty(contents)), t = '';else t = contents{get(handles.plot_type,'Value')};end[st,re] = getdisplayopts(handles.display_opts);if ((isfield(handles.mfbss,'extraplot'))&&(strcmp(t,'Processed Data')))    [f,d] = uiputfile('*.svg','Select output file ...');    if (isempty(f)), return; end    tmpfile = fullfile(d,f);    cnames = mknamespat(1:size(handles.mfbss.A,2),'comp. %d');    ics = cell(size(handles.mfbss.S.map));    grid = handles.mfbss.grid(:,handles.mfbss.S.mask);    for i=1:size(ics,2)        m = unique(handles.mfbss.S.map(:,i));        for j=1:length(m)            A = handles.mfbss.A(handles.mfbss.S.map(:,i)==m(j),i);            tl = handles.mfbss.timeline(handles.mfbss.S.map(:,i)==m(j));            if (sum(handles.mfbss.S.dat(:,m(j)).^2)<eps), continue; end            [ics(min(find(handles.mfbss.S.map(:,i)==m(j))),i),handles.private] = ...                plotallics(handles.mfbss.S.dat(:,m(j)),A(:), ...                {tl},grid,handles.mfbss.mask,{sprintf('%s analysis %s', ...                handles.mfbss.name,cnames{i})},{st,re},handles.private);        end    end    f = fopen(tmpfile,'w');    dat = handles.mfbss.extraplot{1}(handles.mfbss.extraplot{2},ics);    fwrite(f,dat,'char');    fclose(f);end% --- Executes on button press in export_ics.function export_ics_Callback(hObject,eventdata,handles)contents = get(handles.plot_type,'String');if (isempty(contents)), t = '';else t = contents{get(handles.plot_type,'Value')};end[st,re] = getdisplayopts(handles.display_opts);if (isstruct(handles.mfbss.X))    info = getinfo([handles.sequence.timesteps,handles.sequence.dim], ...        size(handles.mfbss.design),sum(handles.mfbss.reference(:)), ...        prod(handles.mfbss.X.dim)*handles.mfbss.X.timesteps, ...        size(handles.mfbss.A,2),handles.mfbss.pre_name, ...        handles.mfbss.name,handles.mfbss.rel_name, ...        handles.mfbss.pos_name, handles.mfbox_filename);else    info = getinfo([handles.sequence.timesteps,handles.sequence.dim], ...        size(handles.mfbss.design),sum(handles.mfbss.reference(:)), ...        length(handles.mfbss.X),size(handles.mfbss.A,2), ...        handles.mfbss.pre_name,handles.mfbss.name,handles.mfbss.rel_name, ...        handles.mfbss.pos_name,handles.mfbox_filename);endtc = {handles.mfbss.timeline};if (~isempty(handles.mfbss.design))    sd = size(handles.mfbss.design);    for i=1:sd(2)        tc{1+i} = interp1(linspace(handles.mfbss.timeline(1), ...            handles.mfbss.timeline(end),sd(1)), ...            handles.mfbss.design(:,i),handles.mfbss.timeline)';    endendif (strcmp(t,'Processed Data'))    [f,d] = uiputfile('*.svg','Select output file ...');    tmpfile = fullfile(d,f);    % mkname!    cnames = mknamespat(1:size(handles.mfbss.A,2),'comp. %d');    ics = zeros(size(handles.mfbss.S.dat,1),size(handles.mfbss.S.map,2),'single');    for i=1:size(ics,2)        ics(:,i) = single(sum(handles.mfbss.S.dat(:,unique(handles.mfbss.S.map(:,i))),2));    end    ics = plotallics(ics,handles.mfbss.A, ...        tc,handles.mfbss.grid(:,handles.mfbss.S.mask), ...        handles.mfbss.mask, ...        mknamespat(cnames,[handles.mfbss.name ' analysis %s']), ...        {st,re},handles.private);    u = triu(handles.mfbss.crosstalk);    l = tril(handles.mfbss.crosstalk);    lp = size(handles.mfbss.crosstalk,1);    % [1,0,0]:=red ...    cross = reshape(u(:)*[1,0,0]+l(:)*[0,0,1],[lp,lp,3])+repmat(eye(lp),[1,1,3]);    reliability = handles.mfbss.reliability;elseif (strcmp(t,'Post-processed Data'))    [f,d] = uiputfile('*.svg','Select output file ...');    tmpfile = fullfile(d,f);    if (isfield(handles.mfbss.ppS,'tag'))        cnames = handles.mfbss.ppS.tag;    else        cnames = mknamespat(1:size(handles.mfbss.ppA,2),'comp. %d');    end    ics = zeros(size(handles.mfbss.ppS.dat,1),size(handles.mfbss.ppS.map,2),'single');    for i=1:size(ics,2)        ics(:,i) = single(sum(handles.mfbss.ppS.dat(:,unique(handles.mfbss.ppS.map(:,i))),2));    end    ics = plotallics(ics,handles.mfbss.ppA, ...        tc,handles.mfbss.grid(:,handles.mfbss.ppS.mask), ...        handles.mfbss.mask, ...        mknamespat(cnames,[handles.mfbss.name ' analysis %s']), ...        {st,re},handles.private);    u = triu(handles.mfbss.ppcrosstalk);    l = tril(handles.mfbss.ppcrosstalk);    lp = size(handles.mfbss.ppcrosstalk,1);    cross = reshape(u(:)*[1,0,0]+l(:)*[0,0,1],[lp,lp,3])+repmat(eye(lp),[1,1,3]);    reliability = handles.mfbss.ppreliability;else    returnendreln = fieldnames(reliability);n = length(ics);nv = 1+floor(max(3,(1+ceil(n/4)))/2)*2;[v,w] = mfbox_mkgrid(nv*ones(1,2));v = v(w>0,:);[p,q] = sort(imag(log(complex(v(:,1)-(nv+1)/2,v(:,2)-(nv+1)/2)*complex(1,-1+eps))));v = v(q,:);r = 1; j = 0; w = zeros(n,2);for i=1:n    if (j>3), r = r+1; j = 0; end    if (j>1), q = nv-r; else, q = r; end    w(i,:) = v(q+(j*(nv-1)),:);    j = j+1;endlrn = length(reln);nrel = floor(100*nv/((n+2)*10+5));f = fopen(tmpfile,'w');fwrite(f,sprintf('<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg width="%1.4fpx" height="%1.4fpx" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">\n', ...    5+100*nv,5+100*(nv+1)+ceil(lrn/nrel)*60),'char');sc = floor(nv/2);for i=1:length(ics)    icn = sprintf('comp %d',i);    fwrite(f,sprintf('<g transform="translate(%1.4f,%1.4f)">\n<g transform="scale(%1.4f,%1.4f)">\n<g id="%s">\n%s\n</g>\n</g>\n</g>\n',5+(w(i,1)-1)*100,5+w(i,2)*100,0.9,0.9,icn,ics{i}),'char');    if (w(i,1)==1)        startp = [100,200+100*(nv-2)*(w(i,2)-1)/(nv-1)];        endp = [-5-sc*25+nv*50,100-sc*25+nv*50+sc*50*(i-0.5)/n];    elseif (w(i,1)==nv)        startp = [100*(nv-1),200+100*(nv-2)*(w(i,2)-1)/(nv-1)];        endp = [5+sc*25+nv*50,100-sc*25+nv*50+sc*50*(i-0.5)/n];    elseif (w(i,2)==1)        startp = [100+100*(nv-2)*(w(i,1)-1)/(nv-1),200];        endp = [-sc*25+nv*50+sc*50*(i-0.5)/n,100-5-sc*25+nv*50];    elseif (w(i,2)==nv)        startp = [100+100*(nv-2)*(w(i,1)-1)/(nv-1),100*nv];        endp = [-sc*25+nv*50+sc*50*(i-0.5)/n,100+5+sc*25+nv*50];    end    fwrite(f,sprintf('<g fill="none" stroke="black" stroke-width="3">\n<line x1="%1.2f" x2="%1.2f" y1="%1.2f" y2="%1.2f"/>\n</g>\n',startp(1),endp(1),startp(2),endp(2)),'char');endfwrite(f,sprintf('<g transform="translate(%1.4f,%1.4f)">\n<g transform="scale(%1.4f,%1.4f)" id="cross">\n%s\n<rect x="0" y="0" width="100" height="100" stroke="black" stroke-width="1" fill="none"/>\n</g><g transform="translate(%1.4f,-1)">\n<text x="0" y="0" font-size="5" font-family="Verdana" text-anchor="end">temporal</text>\n</g>\n<g transform="translate(0,%1.4f)">\n<text x="0" y="0" font-size="5" font-family="Verdana">spatial</text>\n</g>\n</g>\n',-sc*25+nv*50,100-sc*25+nv*50,sc*.5,sc*.5,getsvgimg(cross),sc*50,4+sc*50),'char');for i=1:lrn    fwrite(f,sprintf('<g transform="translate(%1.4f,%1.4f)" id="reliability">\n<g transform="translate(%1.4f,4)"><text x="0" y="0" font-size="6" text-family="Verdana" text-anchor="middle">%s</text>\n</g>\n<rect x="0" y="5" width="%1.4f" height="32" fill="none" stroke="black" stroke-width="1"/>\n', ...        5+mod((i-1),nrel)*((n+2)*10+5),100+100*nv+60*floor((i-1)/nrel), ...        (n+2)*5,reln{i},(n+2)*10),'char');    v = 0.95*reliability.(reln{i}); t = linspace(0,(n+2)*10,length(v)+2); t = t(2:(end-1));    for j=1:length(v)        fwrite(f,sprintf('<rect x="%1.4f" y="%1.4f" width="6" height="%1.4f" fill="gray" stroke="black" stroke-width="1"/>\n<g transform="translate(%1.4f,40)">\n<g transform="rotate(-35)">\n<text x="0" y="0" font-size="4" font-family="Verdana" text-anchor="end">%s</text>\n</g>\n</g>\n',t(j)-3,5+32*(1-v(j)),32*v(j),t(j)+1,cnames{j}));    end    fwrite(f,sprintf('</g>\n'),'char');endfwrite(f,sprintf('<g transform="translate(2.5,2.5)" id="info">\n<rect x="0" y="0" width="%1.4f" height="95" fill="#aaaaff" stroke="black" stroke-width="1" rx="10" ry="10"/>\n',nv*95),'char');for i=1:length(info)    fwrite(f,sprintf('<g transform="translate(10,%1.4f)">\n<text x="0" y="0" font-size="10" font-family="Verdana">%s</text>\n</g>\n',20+(i-1)*10,info{i}),'char');endfwrite(f,sprintf('</g>\n'),'char');fwrite(f,sprintf('</svg>\n'),'char');fclose(f);function d=getsvgimg(img)d = '';img = floor(img*255);s = size(img);for x=1:s(2)    for y=1:s(1)        d = sprintf('%s<rect x="%1.4f" y="%1.4f" width="%1.4f" height="%1.4f" stroke="none" fill="#%02x%02x%02x"/>\n',d,(x-1)*100/s(1),(y-1)*100/s(2),100/s(1),100/s(2),img(y,x,1),img(y,x,2),img(y,x,3));    endendfunction [stdfact,meanrem]=getdisplayopts(h)opts = get(h,'Value');o = [3,2,1,0];stdfact = o(mod(opts-1,4)+1);meanrem = opts>4;function [d,private]=plotallics(S,A,tl,grid,mask,text,opts,private)[bg,private] = mfbox_databackend('getbg',private);[atlas,private] = mfbox_databackend('getatlas',private);s = size(S,2);d = cell(1,s);for i=1:s    tc = A(:,i);    [ic,private] = mfbox_databackend('getic',private,S(:,i),grid,mask);    d{i} = mfbox_plotic(ic,{tc,tl{:}},text{i},opts,bg,atlas);end%function v=getinfo(seq,des,rs,x,c,pren,nb,ren,posn)function v=getinfo(seq,des,rs,x,c,pren,nb,ren,posn,fn)% sequence length(ho

⌨️ 快捷键说明

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