Home > . > prt_ui_disp_weights.m

prt_ui_disp_weights

PURPOSE ^

PRT_UI_DISP_WEIGHTS MATLAB code for prt_ui_disp_weights.fig

SYNOPSIS ^

function varargout = prt_ui_disp_weights(varargin)

DESCRIPTION ^

 PRT_UI_DISP_WEIGHTS MATLAB code for prt_ui_disp_weights.fig

 PRT_UI_DISP_WEIGHTS, by itself, creates a new PRT_UI_DISP_WEIGHTS or raises the
 existing singleton*.

 H = PRT_UI_DISP_WEIGHTS returns the handle to a new PRT_UI_DISP_WEIGHTS or the
 handle to the existing singleton*.

 PRT_UI_DISP_WEIGHTS('CALLBACK',hObject,eventData,handles,...) calls the local
 function named CALLBACK in PRT_UI_DISP_WEIGHTS.M with the given input arguments.

 PRT_UI_DISP_WEIGHTS('Property','Value',...) creates a new PRT_UI_DISP_WEIGHTS or
 raises the existing singleton*.  Starting from the left, property value
 pairs are applied to the GUI before prt_ui_disp_weights_OpeningFcn gets called.
 An unrecognized property name or invalid value makes property application
 stop.  All inputs are passed to prt_ui_disp_weights_OpeningFcn via varargin.

 *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
 instance to run (singleton)".

 See also: GUIDE, GUIDATA, GUIHANDLES
__________________________________________________________________________
 Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = prt_ui_disp_weights(varargin)
0002 % PRT_UI_DISP_WEIGHTS MATLAB code for prt_ui_disp_weights.fig
0003 %
0004 % PRT_UI_DISP_WEIGHTS, by itself, creates a new PRT_UI_DISP_WEIGHTS or raises the
0005 % existing singleton*.
0006 %
0007 % H = PRT_UI_DISP_WEIGHTS returns the handle to a new PRT_UI_DISP_WEIGHTS or the
0008 % handle to the existing singleton*.
0009 %
0010 % PRT_UI_DISP_WEIGHTS('CALLBACK',hObject,eventData,handles,...) calls the local
0011 % function named CALLBACK in PRT_UI_DISP_WEIGHTS.M with the given input arguments.
0012 %
0013 % PRT_UI_DISP_WEIGHTS('Property','Value',...) creates a new PRT_UI_DISP_WEIGHTS or
0014 % raises the existing singleton*.  Starting from the left, property value
0015 % pairs are applied to the GUI before prt_ui_disp_weights_OpeningFcn gets called.
0016 % An unrecognized property name or invalid value makes property application
0017 % stop.  All inputs are passed to prt_ui_disp_weights_OpeningFcn via varargin.
0018 %
0019 % *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
0020 % instance to run (singleton)".
0021 %
0022 % See also: GUIDE, GUIDATA, GUIHANDLES
0023 %__________________________________________________________________________
0024 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory
0025 
0026 % Written by M. J. Rosa and J. Schrouff
0027 % $Id: prt_ui_disp_weights.m 784 2013-08-22 16:43:32Z monteiro $
0028 
0029 % Edit the above text to modify the response to help prt_ui_disp_weights
0030 
0031 % Last Modified by GUIDE v2.5 16-Apr-2014 17:50:09
0032 
0033 % Begin initialization code - DO NOT EDIT
0034 gui_Singleton = 1;
0035 gui_State = struct('gui_Name',       mfilename, ...
0036     'gui_Singleton',  gui_Singleton, ...
0037     'gui_OpeningFcn', @prt_ui_disp_weights_OpeningFcn, ...
0038     'gui_OutputFcn',  @prt_ui_disp_weights_OutputFcn, ...
0039     'gui_LayoutFcn',  [] , ...
0040     'gui_Callback',   []);
0041 if nargin && ischar(varargin{1})
0042     gui_State.gui_Callback = str2func(varargin{1});
0043 end
0044 
0045 if nargout
0046     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0047 else
0048     gui_mainfcn(gui_State, varargin{:});
0049 end
0050 % End initialization code - DO NOT EDIT
0051 
0052 
0053 % --- Executes just before prt_ui_disp_weights is made visible.
0054 function prt_ui_disp_weights_OpeningFcn(hObject, eventdata, handles, varargin)
0055 % This function has no output args, see OutputFcn.
0056 % hObject    handle to figure
0057 % eventdata  reserved - to be defined in a future version of MATLAB
0058 % handles    structure with handles and user data (see GUIDATA)
0059 % varargin   command line arguments to prt_ui_disp_weights (see VARARGIN)
0060 
0061 %if window already exists, just put it as the current figure
0062 Tag='WeightResults';
0063 F = findall(allchild(0),'Flat','Tag',Tag);
0064 if length(F) > 1
0065     % Multiple Graphics windows - close all but most recent
0066     close(F(2:end))
0067     F = F(1);
0068     uistack(F,'top')
0069 elseif length(F)==1
0070     uistack(F,'top')
0071 else
0072     set(handles.figure1,'Tag',Tag)
0073     set(handles.figure1,'Name','PRoNTo :: Model interpretation')
0074     set(handles.figure1,'MenuBar','figure','WindowStyle','normal');
0075     
0076     %set size of the window, taking screen resolution and platform into account
0077     %--------------------------------------------------------------------------
0078     S0= spm('WinSize','0',1);   %-Screen size (of the current monitor)
0079     if ispc
0080         PF='MS Sans Serif';
0081     else
0082         PF= spm_platform('fonts');     %-Font names (for this platform)
0083         PF=PF.helvetica;
0084     end
0085     tmp  = [S0(3)/1280 (S0(4))/800];
0086     ratio=min(tmp)*[1 1 1 1];
0087     FS = 1 + 0.85*(min(ratio)-1);  %factor to scale the fonts
0088     x=get(handles.figure1,'Position');
0089     set(handles.figure1,'Position',ratio.*x)
0090     set(handles.figure1,'Resize','on')
0091     
0092     
0093     color=prt_get_defaults('color');
0094     set(handles.figure1,'Color',color.bg1)
0095     aa=get(handles.figure1,'children');
0096     for i=1:length(aa)
0097         if strcmpi(get(aa(i),'type'),'uipanel')
0098             set(aa(i),'BackgroundColor',color.bg2)
0099             bb=get(aa(i),'children');
0100             if ~isempty(bb)
0101                 for j=1:length(bb)
0102                     if strcmpi(get(bb(j),'type'),'uipanel')
0103                         cc=get(bb(j),'children');
0104                         set(bb(j),'BackgroundColor',color.bg2)
0105                         for k=1:length(cc)
0106                             if strcmpi(get(cc(k),'type'),'uipanel')
0107                                 dd=get(cc(k),'children');
0108                                 set(cc(k),'BackgroundColor',color.bg2)
0109                                 for l=1:length(dd)
0110                                     if strcmpi(get(dd(l),'type'),'uicontrol')
0111                                         if ~isempty(find(strcmpi(get(dd(l),'Style'),{'text',...
0112                                                 'radiobutton','checkbox'})))
0113                                             set(dd(l),'BackgroundColor',color.bg2)
0114                                         elseif ~isempty(find(strcmpi(get(dd(l),'Style'),'pushbutton')))
0115                                             set(dd(l),'BackgroundColor',color.fr)
0116                                         end
0117                                     end
0118                                     set(dd(l),'FontUnits','pixel')
0119                                     xf=get(dd(l),'FontSize');
0120                                     if ispc
0121                                         set(dd(l),'FontSize',ceil(FS*xf),'FontName',PF,...
0122                                             'FontUnits','normalized','Units','normalized')
0123                                     else
0124                                         set(dd(l),'FontSize',ceil(FS*xf),'FontName',PF,...
0125                                             'Units','normalized')
0126                                     end
0127                                 end
0128                             elseif strcmpi(get(cc(k),'type'),'uicontrol') && ...
0129                                     ~isempty(find(strcmpi(get(cc(k),'Style'),{'text',...
0130                                     'radiobutton','checkbox'})))
0131                                 set(cc(k),'BackgroundColor',color.bg2)
0132                             elseif strcmpi(get(cc(k),'type'),'uicontrol')&& ...
0133                                     ~isempty(find(strcmpi(get(cc(k),'Style'),'pushbutton')))
0134                                 set(cc(k),'BackgroundColor',color.fr)
0135                             end
0136                             set(cc(k),'FontUnits','pixel')
0137                             xf=get(cc(k),'FontSize');
0138                             set(cc(k),'FontSize',ceil(FS*xf),'FontName',PF,...
0139                                 'Units','normalized')
0140                         end
0141                     elseif strcmpi(get(bb(j),'type'),'uicontrol') && ...
0142                             ~isempty(find(strcmpi(get(bb(j),'Style'),{'text',...
0143                             'radiobutton','checkbox'})))
0144                         set(bb(j),'BackgroundColor',color.bg2)
0145                     elseif strcmpi(get(bb(j),'type'),'uicontrol') && ...
0146                             ~isempty(find(strcmpi(get(bb(j),'Style'),'pushbutton')))
0147                         set(bb(j),'BackgroundColor',color.fr)
0148                     end
0149                     set(bb(j),'FontUnits','pixel')
0150                     xf=get(bb(j),'FontSize');
0151                     set(bb(j),'FontSize',ceil(FS*xf),'FontName',PF,...
0152                         'Units','normalized')
0153                 end
0154             end
0155         elseif strcmpi(get(aa(i),'type'),'uicontrol')
0156             if ~isempty(find(strcmpi(get(aa(i),'Style'),{'text',...
0157                     'radiobutton','checkbox'})))
0158                 set(aa(i),'BackgroundColor',color.bg1)
0159             elseif ~isempty(find(strcmpi(get(aa(i),'Style'),'pushbutton')))
0160                 set(aa(i),'BackgroundColor',color.fr)
0161             end
0162         end
0163         if ~strcmpi(get(aa(i),'type'),'uimenu')
0164             set(aa(i),'FontUnits','pixel')
0165             xf=get(aa(i),'FontSize');
0166             set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
0167                 'Units','normalized')
0168         end
0169     end
0170     
0171     
0172     % Initialize window
0173     % -------------------------------------------------------------------------
0174     
0175     if ~isfield(handles,'notinit')
0176         
0177         % Load PRT.mat
0178         PRT     = spm_select(1,'mat','Select PRT.mat',[],pwd,'PRT.mat');
0179         if isempty(PRT)
0180             error('prt_ui_disp_weights:NoPRT','No PRT file selected')        
0181         end
0182 
0183         pathdir = regexprep(PRT,'PRT.mat', '');
0184         handles.pathdir = pathdir;
0185         handles.prtdir=fileparts(PRT);
0186         load(PRT);
0187         
0188         % Save PRT
0189         handles.PRT = PRT;
0190         
0191         % Flag to load new weights
0192         handles.noloadw = 0;
0193         
0194         % Load model names
0195         if ~isfield(PRT,'model')
0196             error('No models found in PRT.mat!')
0197         end
0198         
0199         
0200         nmodels = length(PRT.model);
0201         mi  = [];
0202         nmi = 0;
0203         nmroi = 0;
0204         for m = 1:nmodels
0205             if isfield(PRT.model(m),'input') && ~isempty(PRT.model(m).input)
0206                 if isfield(PRT.model(m),'output') && ~isempty(PRT.model(m).output)
0207                     if isfield(PRT.model(m).output,'weight_img') && ~isempty(PRT.model(m).output.weight_img)
0208                         nmi = nmi +1;
0209                         model_name{nmi} = PRT.model(m).model_name;
0210                         mi = [mi, m];
0211                         if isfield(PRT.model(m).output,'weight_ROI') && ...
0212                                 ~isempty(PRT.model(m).output.weight_ROI)
0213                             nmroi = nmroi+1;
0214                         end
0215                     else
0216                         disp(sprintf('Weights not computed for model %s ! It will not be displayed',PRT.model(m).model_name));
0217                     end
0218                 else
0219                     beep;
0220                     disp(sprintf('Weights not computed for model %s ! It will not be displayed',PRT.model(m).model_name));
0221                 end
0222             else
0223                 beep;
0224                 disp(sprintf('Model %s not properly specified! It will not be displayed',PRT.model(m).model_name));
0225             end
0226             
0227         end
0228         %         if ~nmi, error('There are no estimated/good models in this
0229         %         PRT!'); end
0230         
0231         if nmi
0232             handles.mi = mi;
0233             
0234             % Set model pulldown menu
0235             handles.mnames = model_name;
0236             set(handles.classmenu,'String',handles.mnames);
0237             
0238             % Get folds pulldown menu
0239             m             = get(handles.classmenu,'Value');
0240             handles.nfold = length(PRT.model(mi(m)).output.fold);
0241             folds{1}      = 'All folds / Average';
0242             for f = 1:handles.nfold
0243                 folds{f+1} = num2str(f);
0244             end
0245             handles.folds = folds;
0246             set(handles.foldmenu,'String',handles.folds);
0247             set(handles.foldmenu,'Value',1);
0248             
0249             list = handles.PRT.model(mi(m)).output.weight_img;
0250             if ~isempty(list)
0251                 set(handles.imagemenu,'String',list)
0252                 set(handles.imagemenu,'Value',1)
0253             else
0254                 set(handles.imagemenu,'Enable','off')
0255             end
0256             
0257             
0258         end
0259         % Initialize model button
0260         handles.model_button = 0;
0261         
0262         % Deal with ROI table and bar graph: 1st turned off
0263         set(handles.axes1, 'visible','off')
0264         set(handles.ROItable,'visible','off')
0265         handles.selectedcell = [];
0266         handles.labels=cell(nmodels,1);
0267         set(handles.butt_load_labels,'visible','off');
0268         set(handles.saveweight,'visible','off');
0269         set(handles.modtable,'Visible','off')
0270         set(handles.modtable,'Enable','off')
0271         % Clear axes
0272         cla(handles.axes1);
0273     end
0274 end
0275 set(handles.disp_voxels,'Value',1)
0276 set(handles.disp_voxels,'Enable','off')
0277 set(handles.disp_regions,'Value',0)
0278 set(handles.disp_regions,'Enable','off')
0279 % Choose default command line output for prt_ui_disp_weights
0280 handles.output = hObject;
0281 
0282 % Update handles structure
0283 guidata(hObject, handles);
0284 
0285 % UIWAIT makes prt_ui_disp_weights wait for user response (see UIRESUME)
0286 % uiwait(handles.figure1);
0287 
0288 
0289 % --- Outputs from this function are returned to the command line.
0290 function varargout = prt_ui_disp_weights_OutputFcn(hObject, eventdata, handles)
0291 % varargout  cell array for returning output args (see VARARGOUT);
0292 % hObject    handle to figure
0293 % eventdata  reserved - to be defined in a future version of MATLAB
0294 % handles    structure with handles and user data (see GUIDATA)
0295 
0296 % Get default command line output from handles structure
0297 varargout{1} = handles.output;
0298 
0299 
0300 % --- Executes on button press in originbutton.
0301 function originbutton_Callback(hObject, eventdata, handles)
0302 % hObject    handle to originbutton (see GCBO)
0303 % eventdata  reserved - to be defined in a future version of MATLAB
0304 % handles    structure with handles and user data (see GUIDATA)
0305 
0306 % Reset the crosshairs position
0307 % -------------------------------------------------------------------------
0308 if isfield(handles,'img')
0309     spm_orthviews('Reposition',[0 0 0]);
0310 end
0311 
0312 function mmedit_Callback(hObject, eventdata, handles)
0313 % hObject    handle to mmedit (see GCBO)
0314 % eventdata  reserved - to be defined in a future version of MATLAB
0315 % handles    structure with handles and user data (see GUIDATA)
0316 
0317 % Hints: get(hObject,'String') returns contents of mmedit as text
0318 %        str2double(get(hObject,'String')) returns contents of mmedit as a double
0319 
0320 % Move crosshairs position in mm
0321 % -------------------------------------------------------------------------
0322 if isfield(handles,'img')
0323     mp    = handles.mmedit;
0324     posmm = get(mp,'String');
0325     pos = sscanf(posmm, '%g %g %g');
0326     if length(pos)~=3
0327         pos = spm_orthviews('Pos');
0328     end
0329     spm_orthviews('Reposition',pos);
0330 end
0331 
0332 % --- Executes during object creation, after setting all properties.
0333 function mmedit_CreateFcn(hObject, eventdata, handles)
0334 % hObject    handle to mmedit (see GCBO)
0335 % eventdata  reserved - to be defined in a future version of MATLAB
0336 % handles    empty - handles not created until after all CreateFcns called
0337 
0338 % Hint: edit controls usually have a white background on Windows.
0339 %       See ISPC and COMPUTER.
0340 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0341     set(hObject,'BackgroundColor','white');
0342 end
0343 
0344 
0345 function vxedit_Callback(hObject, eventdata, handles)
0346 % hObject    handle to vxedit (see GCBO)
0347 % eventdata  reserved - to be defined in a future version of MATLAB
0348 % handles    structure with handles and user data (see GUIDATA)
0349 
0350 % Hints: get(hObject,'String') returns contents of vxedit as text
0351 %        str2double(get(hObject,'String')) returns contents of vxedit as a double
0352 
0353 % Move crosshairs position in vx
0354 % -------------------------------------------------------------------------
0355 if isfield(handles,'img')
0356     mp    = handles.vxedit;
0357     posvx = get(mp,'String');
0358     pos   = sscanf(posvx, '%g %g %g');
0359     if length(pos)~=3
0360         pos = spm_orthviews('pos',1);
0361     end
0362     tmp = handles.vols{1}.mat;
0363     pos = tmp(1:3,:)*[pos ; 1];
0364     spm_orthviews('Reposition',pos);
0365 end
0366 
0367 
0368 % --- Executes during object creation, after setting all properties.
0369 function vxedit_CreateFcn(hObject, eventdata, handles)
0370 % hObject    handle to vxedit (see GCBO)
0371 % eventdata  reserved - to be defined in a future version of MATLAB
0372 % handles    empty - handles not created until after all CreateFcns called
0373 
0374 % Hint: edit controls usually have a white background on Windows.
0375 %       See ISPC and COMPUTER.
0376 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0377     set(hObject,'BackgroundColor','white');
0378 end
0379 
0380 
0381 % --- Executes on button press in quitbutton.
0382 function quitbutton_Callback(hObject, eventdata, handles)
0383 % hObject    handle to quitbutton (see GCBO)
0384 % eventdata  reserved - to be defined in a future version of MATLAB
0385 % handles    structure with handles and user data (see GUIDATA)
0386 
0387 % Close and clear figure
0388 % -------------------------------------------------------------------------
0389 close(handles.figure1);
0390 
0391 
0392 function loadweight_Callback(hObject, eventdata, handles)
0393 % hObject    handle to loadweight (see GCBO)
0394 % eventdata  reserved - to be defined in a future version of MATLAB
0395 % handles    structure with handles and user data (see GUIDATA)
0396 
0397 % Hints: get(hObject,'String') returns contents of loadweight as text
0398 %        str2double(get(hObject,'String')) returns contents of loadweight as a double
0399 
0400 
0401 % --- Executes during object creation, after setting all properties.
0402 function loadweight_CreateFcn(hObject, eventdata, handles)
0403 % hObject    handle to loadweight (see GCBO)
0404 % eventdata  reserved - to be defined in a future version of MATLAB
0405 % handles    empty - handles not created until after all CreateFcns called
0406 
0407 % Hint: edit controls usually have a white background on Windows.
0408 %       See ISPC and COMPUTER.
0409 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0410     set(hObject,'BackgroundColor','white');
0411 end
0412 
0413 
0414 % --- Executes on button press in weightbutton.
0415 function weightbutton_Callback(hObject, eventdata, handles)
0416 % hObject    handle to weightbutton (see GCBO)
0417 % eventdata  reserved - to be defined in a future version of MATLAB
0418 % handles    structure with handles and user data (see GUIDATA)
0419 
0420 disp('Loading weights...>>')
0421 % Select results (.img) for weight map
0422 % -------------------------------------------------------------------------
0423 if ~isfield(handles,'wmap') || ~handles.noloadw
0424     wmap            = spm_select(1,'image','Select weight map.');
0425     % Remove number in file name
0426     if strcmp(wmap(end-1),',')
0427         wmap = wmap(1:end-2);
0428     end
0429     V               = spm_vol(wmap);
0430     handles.vols{1} = V;
0431     handles.wmap    = wmap;
0432     
0433 end
0434 
0435 spm_orthviews('Reset');
0436 gcfchil = get(gcf,'Children');
0437 for i=1:length(gcfchil)
0438     if strcmpi(get(gcfchil(i),'Type'),'axes')
0439         delete(gcfchil(i)) % Delete any left-over colorbar
0440     end
0441 end
0442 
0443 % Image dimensions
0444 % -------------------------------------------------------------------------
0445 fold          = get(handles.foldmenu,'Value')-1;
0446 Vfolds        = handles.vols{1};
0447 V             = Vfolds(1);
0448 M             = V.mat;
0449 DIM           = V.dim(1:3)';
0450 xdim          = DIM(1); ydim  = DIM(2); zdim  = DIM(3);
0451 if length(V.private.dat.dim) < 4
0452     fdim = 1;                       % Handle 3D images
0453 else
0454     fdim = V.private.dat.dim(4);    % Handle 4D images
0455 end
0456 [xords,yords] = ndgrid(1:xdim,1:ydim);
0457 xords         = xords(:)';  yords = yords(:)';
0458 I             = 1:xdim*ydim;
0459 zords_init    = ones(1,xdim*ydim);
0460 
0461 if ~isempty(handles.selectedcell)
0462     matroi = NaN * ones(xdim,ydim,zdim);
0463     idroi = handles.idfeat_roi{handles.sort_roi(handles.selectedcell(1))};
0464     matroi(idroi) = 1;
0465     handles.roimatdisp = matroi;
0466 else
0467     matroi = ones(xdim,ydim,zdim);
0468     handles.roimatdisp = matroi;
0469 end
0470 
0471 % Get image values above zero for each fold and all folds
0472 % -------------------------------------------------------------------------
0473 xyz_above = [];
0474 z_above   = [];
0475 if fold == 0,
0476     fold_coord = fdim*ones(1,xdim*ydim);
0477     V = Vfolds(fdim);
0478 else
0479     fold_coord = fold*ones(1,xdim*ydim);
0480     V = Vfolds(fold);
0481 end
0482 
0483 for z = 1:zdim,
0484     zords = z*zords_init;
0485     xyz   = [xords(I); yords(I); zords(I); fold_coord];
0486     zvals = spm_get_data(V,xyz);
0487     if isfield(handles,'roimatdisp') && ~isempty(handles.roimatdisp)
0488         indmask = sub2ind([xdim,ydim,zdim],xords(I)', yords(I)', zords(I)');
0489         mroi = handles.roimatdisp(indmask);
0490         zvals = zvals.*mroi';
0491     end
0492     above = find(~isnan(zvals));
0493     if length(above)==length(zvals) %old version of weight computation
0494         above = find(zvals~=0);
0495     end
0496     if ~isempty(above)
0497         xyz_above = [xyz_above,xyz(:,above)];
0498         z_above   = [z_above,zvals(above)];
0499     end
0500 end
0501 XYZ   = xyz_above(1:3,:);
0502 Z     = z_above;
0503 
0504 %compute center of gravity to reposition crosshairs
0505 xm = round(median(XYZ(1,:)));
0506 ym = round(median(XYZ(2,:)));
0507 zm = round(median(XYZ(3,:)));
0508 % xmin = min(XYZ(1,:));
0509 % xmax = max(XYZ(1,:));
0510 % xfov =xmax-xmin;
0511 % Set spm_orthviews properties
0512 % -------------------------------------------------------------------------
0513 rotate3d off
0514 global st
0515 
0516 handles.notinit = 1;
0517 handles.img     = 1;
0518 
0519 st.handles  = handles;
0520 st.fig      = handles.figure1;
0521 st.V        = V;
0522 st.callback = 'prt_ui_results(''showpos'')';
0523 
0524 % Display maps
0525 % -------------------------------------------------------------------------
0526 [BB vx] = spm_get_bbox(handles.wmap);
0527 xax = BB(1,1):abs(vx(1)):BB(2,1);
0528 yax = BB(1,2):abs(vx(2)):BB(2,2);
0529 zax = BB(1,3):abs(vx(3)):BB(2,3);
0530 
0531 h  = spm_orthviews('Image', handles.wmap,[0.0519 0.498 0.4182 0.3951]);
0532 handles.wimgh = h;
0533 spm_orthviews('AddContext', h);
0534 spm_orthviews('MaxBB');
0535 spm_orthviews('AddBlobs', h, XYZ, Z, M);
0536 cmap = get(gcf,'Colormap');
0537 if size(cmap,1)~=128
0538     spm_figure('Colormap','jet');
0539 end
0540 spm_orthviews('Reposition',[sign(vx(1))*xax(xm),sign(vx(2))*yax(ym),sign(vx(3))*zax(zm)])
0541 % spm_orthviews('Zoom',(xfov*abs(vx(1))))
0542 spm_orthviews('Redraw');
0543 
0544 if isfield(handles,'aimg')
0545     anatomicalbutton_Callback(hObject, eventdata, handles);
0546 end
0547 
0548 % Show positions
0549 % -------------------------------------------------------------------------
0550 prt_ui_results('showpos');
0551 
0552 disp('Done');
0553 
0554 % Reset flag to load weights
0555 handles.noloadw = 1;
0556 
0557 % Show file name
0558 % -------------------------------------------------------------------------
0559 set(handles.loadweight,'String',handles.wmap);
0560 guidata(hObject, handles);
0561 
0562 function loadanatomical_Callback(hObject, eventdata, handles)
0563 % hObject    handle to loadanatomical (see GCBO)
0564 % eventdata  reserved - to be defined in a future version of MATLAB
0565 % handles    structure with handles and user data (see GUIDATA)
0566 
0567 % Hints: get(hObject,'String') returns contents of loadanatomical as text
0568 %        str2double(get(hObject,'String')) returns contents of loadanatomical as a double
0569 
0570 
0571 % --- Executes during object creation, after setting all properties.
0572 function loadanatomical_CreateFcn(hObject, eventdata, handles)
0573 % hObject    handle to loadanatomical (see GCBO)
0574 % eventdata  reserved - to be defined in a future version of MATLAB
0575 % handles    empty - handles not created until after all CreateFcns called
0576 
0577 % Hint: edit controls usually have a white background on Windows.
0578 %       See ISPC and COMPUTER.
0579 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0580     set(hObject,'BackgroundColor','white');
0581 end
0582 
0583 
0584 % --- Executes on button press in anatomicalbutton.
0585 function anatomicalbutton_Callback(hObject, eventdata, handles)
0586 % hObject    handle to anatomicalbutton (see GCBO)
0587 % eventdata  reserved - to be defined in a future version of MATLAB
0588 % handles    structure with handles and user data (see GUIDATA)
0589 
0590 % Check if weight map and anatomical image exist and reset orthviews
0591 % -------------------------------------------------------------------------
0592 if ~isfield(handles,'wmap')
0593     spm_orthviews('Reset');
0594 end
0595 global st
0596 st.fig = handles.figure1;
0597 if ~isfield(handles,'aimg') || ~handles.noloadi
0598     img    = spm_select(1,'image','Select anatomical image.');
0599 else
0600     img = handles.aimg;
0601 end
0602 
0603 % Show anatomical image
0604 % -------------------------------------------------------------------------
0605 rotate3d off
0606 st.fig = handles.figure1;
0607 handle = spm_orthviews('Image', img, [0.5595 0.498 0.4182 0.3951]);
0608 cmap   = get(gcf,'Colormap');
0609 if size(cmap,1)~=128
0610     spm_figure('Colormap','gray')
0611 end
0612 
0613 handles.aimgh   = handle;
0614 handles.aimg    = img;
0615 handles.img     = 1;
0616 handles.noloadi = 1;
0617 
0618 % Show file name
0619 % -------------------------------------------------------------------------
0620 set(handles.loadanatomical,'String',handles.aimg);
0621 
0622 guidata(hObject, handles);
0623 
0624 
0625 % --- Executes on selection change in foldmenu.
0626 function foldmenu_Callback(hObject, eventdata, handles)
0627 % hObject    handle to foldmenu (see GCBO)
0628 % eventdata  reserved - to be defined in a future version of MATLAB
0629 % handles    structure with handles and user data (see GUIDATA)
0630 
0631 % Hints: contents = cellstr(get(hObject,'String')) returns foldmenu contents as cell array
0632 %        contents{get(hObject,'Value')} returns selected item from foldmenu
0633 
0634 % Change weight map
0635 % -------------------------------------------------------------------------
0636 if ~handles.model_button
0637     if isfield(handles,'vols')
0638         handles.noloadw = 1;
0639         handles.selectedcell = [];
0640         weightbutton_Callback(hObject, eventdata, handles);
0641     end
0642 end
0643 
0644 % Update table and bar graph
0645 m  = get(handles.classmenu,'Value');
0646 if m==0
0647     m=1;
0648 end
0649 mi = handles.mi;
0650 ffi = get(handles.foldmenu,'Value')-1;
0651 if ffi == -1 % for Mac issues with popup menus
0652     ffi = 0;
0653 end
0654 if ffi==0 % for average
0655     ffi=length(get(handles.foldmenu,'String'));
0656 end
0657 if isfield(handles.PRT.model(mi(m)).output,'weight_ROI') &&... % chosen model has ROI values
0658        ~isempty(handles.PRT.model(mi(m)).output.weight_ROI)
0659    dat = handles.dattable;
0660    weights = handles.PRT.model(mi(m)).output.weight_ROI{handles.class}(:,ffi)*100;
0661    dat(:,2) = num2cell(weights);
0662    [vald,idwroi] = sort(weights,'descend');
0663    dat = dat(idwroi,:);
0664    set(handles.ROItable,'Data',dat);
0665    set(handles.ROItable,'visible','on');
0666    set(handles.butt_load_labels,'visible','on');
0667    
0668    %Bar graph to show decrease in ROI weights
0669    set(handles.axes1,'visible','on')
0670    bar(handles.axes1,weights(idwroi));
0671    set(get(handles.axes1,'XLabel'),'FontWeight','demi')
0672    set(get(handles.axes1,'XLabel'),'String','ROI index')
0673    set(get(handles.axes1,'YLabel'),'String','ROI weight')
0674    set(get(handles.axes1,'YLabel'),'FontWeight','demi')    
0675    
0676    if ~isempty(handles.datmod)
0677        datmod = handles.datmod;
0678        wemod = zeros(length(handles.nmods),handles.nfold+1);
0679         for i=1:length(handles.nmods) % get all the modalities
0680             wemod(i,:) = [handles.PRT.model(mi(m)).output.weight_MOD{i}];
0681         end
0682         datmod(:,2) = num2cell(wemod(:,ffi)*100);
0683         [vald,idwmod] = sort(wemod(:,ffi),'descend');
0684         datmod= datmod(idwmod,:);
0685         set(handles.modtable,'Data',datmod)
0686         set(handles.modtable,'Visible','on')
0687    end
0688 end
0689 guidata(hObject, handles);
0690 
0691 
0692 
0693 
0694 % --- Executes during object creation, after setting all properties.
0695 function foldmenu_CreateFcn(hObject, eventdata, handles)
0696 % hObject    handle to foldmenu (see GCBO)
0697 % eventdata  reserved - to be defined in a future version of MATLAB
0698 % handles    empty - handles not created until after all CreateFcns called
0699 
0700 % Hint: popupmenu controls usually have a white background on Windows.
0701 %       See ISPC and COMPUTER.
0702 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0703     set(hObject,'BackgroundColor','white');
0704 end
0705 
0706 
0707 % --- Executes on selection change in classmenu.
0708 function classmenu_Callback(hObject, eventdata, handles)
0709 % hObject    handle to classmenu (see GCBO)
0710 % eventdata  reserved - to be defined in a future version of MATLAB
0711 % handles    structure with handles and user data (see GUIDATA)
0712 
0713 % Hints: contents = cellstr(get(hObject,'String')) returns classmenu contents as cell array
0714 %        contents{get(hObject,'Value')} returns selected item from classmenu
0715 
0716 % Hints: contents = cellstr(get(hObject,'String')) returns classmenu contents as cell array
0717 %        contents{get(hObject,'Value')} returns selected item from classmenu
0718 m  = get(handles.classmenu,'Value');
0719 if m==0
0720     m=1;
0721 end
0722 mi = handles.mi;
0723 
0724 % Set the list of weight images generated for this model
0725 list = handles.PRT.model(mi(m)).output.weight_img;
0726 if ~isempty(list)
0727     set(handles.imagemenu,'String',list)
0728 else
0729     set(handles.imagemenu,'Enable','off')
0730 end
0731 set(handles.imagemenu,'Value',1);
0732 handles.class = 1;
0733 
0734 % Get the modalities in the model if multiple kernels and multiple
0735 % modalities
0736 in.fs_name = handles.PRT.model(mi(m)).input.fs(1).fs_name;
0737 fid = prt_init_fs(handles.PRT,in);
0738 handles.fid = fid;
0739 if ~isempty(strfind(handles.PRT.model(mi(m)).input.machine.function,'MKL')) && ...
0740         handles.PRT.fs(fid).multkernel
0741     nmod = length(handles.PRT.fs(fid).modality);
0742     mods = cell(nmod,1);
0743     for i=1:nmod
0744         mods{i} = handles.PRT.fs(fid).modality(i).mod_name;
0745     end
0746     handles.summed = 0;
0747 elseif ~isempty(strfind(handles.PRT.model(mi(m)).input.machine.function,'MKL')) && ...
0748         ~handles.PRT.fs(fid).multkernel
0749     mods{1} = handles.PRT.fs(fid).modality(1).mod_name;
0750     handles.summed = 0; % either summed modalities or only one
0751 else
0752     mods{1} = handles.PRT.fs(fid).modality(1).mod_name;
0753     handles.summed = 1; % either summed modalities or only one
0754 end
0755 handles.nmods = mods;
0756 guidata(hObject, handles);
0757 imagemenu_Callback(hObject,eventdata,handles)
0758 handles = guidata(hObject);
0759 guidata(hObject, handles);
0760 
0761 
0762 % --- Executes during object creation, after setting all properties.
0763 function classmenu_CreateFcn(hObject, eventdata, handles)
0764 % hObject    handle to classmenu (see GCBO)
0765 % eventdata  reserved - to be defined in a future version of MATLAB
0766 % handles    empty - handles not created until after all CreateFcns called
0767 
0768 % Hint: popupmenu controls usually have a white background on Windows.
0769 %       See ISPC and COMPUTER.
0770 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0771     set(hObject,'BackgroundColor','white');
0772 end
0773 
0774 % --- Executes on selection change in imagemenu.
0775 function imagemenu_Callback(hObject, eventdata, handles)
0776 % hObject    handle to imagemenu (see GCBO)
0777 % eventdata  reserved - to be defined in a future version of MATLAB
0778 % handles    structure with handles and user data (see GUIDATA)
0779 
0780 % Hints: contents = get(hObject,'String') returns imagemenu contents as cell array
0781 %        contents{get(hObject,'Value')} returns selected item from imagemenu
0782 % Get models (classmenu), classes (imagemenu) and folds (foldmenu)
0783 m  = get(handles.classmenu,'Value');
0784 if m==0
0785     m=1;
0786 end
0787 mi = handles.mi;
0788 handles.nfold = length(handles.PRT.model(mi(m)).output.fold);
0789 
0790 
0791 folds{1}      = 'All folds / Average';
0792 for f = 1:handles.nfold
0793     folds{f+1} = num2str(f);
0794 end
0795 
0796 % Set folds and call fold function to plot the weights for that model
0797 handles.folds = folds;
0798 set(handles.foldmenu,'String',handles.folds);
0799 
0800 disp_vox = get(handles.disp_voxels,'Value');
0801 set(handles.disp_voxels,'Enable','on')
0802 
0803 %get the fold to display
0804 ffi = get(handles.foldmenu,'Value')-1;
0805 if ffi == -1 % for Mac issues with popup menus
0806     ffi = 0;
0807 end
0808 if ffi==0 % for average
0809     ffi=length(get(handles.foldmenu,'String'));
0810 end
0811 
0812 % get the image to display
0813 handles.class = get(handles.imagemenu,'Value');
0814 if handles.class ==0
0815     handles.class = 1;
0816 end
0817 
0818 % Compare the name of the image with the name of the modalities to obtain
0819 % the index of the modality
0820 nim = get(handles.imagemenu,'String');
0821 for i = 1:length(handles.nmods)
0822     if ~isempty(strfind(nim,char(handles.nmods{i})))
0823         mids = i;
0824     end
0825 end
0826 
0827 
0828 % Initialize the table
0829 % -------------------------------------------------------------------------
0830 
0831 flagmodMKL = 0; % One weight per modality?
0832 
0833 % chosen model has ROI values or weights per modality : create the table
0834 if isfield(handles.PRT.model(mi(m)).output,'weight_ROI') &&... 
0835        ~isempty(handles.PRT.model(mi(m)).output.weight_ROI)
0836    
0837    in = struct();
0838    in.fs_name = handles.PRT.model(mi(m)).input.fs(1).fs_name;
0839    fid = prt_init_fs(handles.PRT,in);
0840    % For each modality if multiple modalities in multiple kernel settings
0841    if handles.PRT.fs(fid).multkernel && ~handles.summed
0842        stm = length(handles.nmods); %if multiple modalities used in multiple kernels
0843    else
0844        stm =1; % if modalities concatenated or only one
0845    end
0846    if ~iscell(handles.PRT.fs(fid).atlas_name)
0847        handles.PRT.fs(fid).atlas_name = {handles.PRT.fs(fid).atlas_name};
0848    end
0849    % Get the number of ROIs and their labels for each modality
0850    handles.num_roi = [];
0851    
0852    for i = 1:stm
0853        if isfield(handles.PRT.fs(fid).modality(i),'num_ROI') && ~handles.summed
0854             num_roi = handles.PRT.fs(fid).modality(i).num_ROI; % MKL on regions
0855             atl_name = handles.PRT.fs(fid).atlas_name{i};
0856        else
0857            num_roi = 1:size(handles.PRT.model(mi(m)).output.weight_ROI{handles.class},1);
0858            if isfield(handles.PRT.model(mi(m)).output,'weight_atlas') && ...
0859                    ~isempty(handles.PRT.model(mi(m)).output.weight_atlas)
0860                 atl_name = handles.PRT.model(mi(m)).output.weight_atlas{i} ; %summarized weights
0861            else
0862                atl_name = []; %MKL on modalities
0863            end
0864        end
0865        handles.num_roi(:,i) = num_roi;
0866        
0867        % Get the labels if they are stored in a .mat along the atlas file for
0868        % MKL on regions and summarisation
0869        if ~isempty(atl_name)
0870            [a,b]=fileparts(atl_name);
0871            try
0872                load(fullfile(a,['Labels_',b,'.mat']))
0873                try
0874                    handles.labels{mi(m)}{i}=ROI_names;
0875                catch
0876                    disp('No variable ROI_names found, generic names used')
0877                end
0878            catch
0879                  disp('No file containing the names of the ROIs found, generic names used')
0880            end
0881            if ~isfield(handles,'labels') || ...
0882                    isempty(handles.labels{mi(m)}) || ...
0883                    isempty(handles.labels{mi(m)}{i})
0884                label=cell(length(num_roi),1);
0885                for j=1:length(num_roi)
0886                    label{j} = ['ROI_',num2str(num_roi(j))];
0887                end
0888            else
0889                if isfield(handles.PRT.fs(fid),'igood_kerns') && ...
0890                        length(handles.PRT.fs(fid).igood_kerns)==length(num_roi) &&...
0891                        ~handles.summed
0892                     label = handles.labels{mi(m)}{i}(handles.PRT.fs(fid).igood_kerns); %take 0 kernels out
0893                     handles.num_roi(:,i) = handles.PRT.fs(fid).igood_kerns;
0894                else
0895                    try
0896                        label = handles.labels{mi(m)}{i}(num_roi);
0897                    catch
0898                        if length(num_roi)==length(handles.labels{mi(m)}{i})  % match between labels and number of regions
0899                            label = handles.labels{mi(m)}{i}(num_roi);
0900                            handles.num_roi(:,i) = num_roi;
0901                        elseif length(num_roi)==length(handles.labels{mi(m)}{i})+1    %missing the 'others' region
0902                            handles.labels{mi(m)}{i} = [{'others'};handles.labels{mi(m)}{i}];
0903                            label = handles.labels{mi(m)}{i}(num_roi);
0904                            handles.num_roi(:,i) = num_roi;
0905                        else
0906                            warning('prt_ui_disp_weights:LabelsDoNotCorrespondtoROI',... % could not use file
0907                                'Number of labels in .mat does not correspond to number of ROIs');
0908                            label=cell(length(num_roi(:,i)),1);
0909                            for j=1:length(num_roi(:,i))
0910                                label{j} = ['ROI_',num2str(num_roi(j,i))];
0911                            end
0912                        end
0913                    end
0914 
0915                end
0916            end 
0917            lc = {'ROI label','ROI weight (%)'};
0918            xlabel = 'Index in table';
0919            ylabel = 'Weight';
0920            set(handles.butt_load_labels,'Visible','on')
0921            set(handles.saveweight,'Visible','on')
0922        else %get names of the modalities for MKL on modalities
0923            label = cell(length(handles.PRT.fs(fid).modality),1);
0924            for j = 1:length(handles.PRT.fs(fid).modality)
0925                label{j} = char(handles.PRT.fs(fid).modality(j).mod_name);
0926            end
0927            lc = {'Modality','Mod. weight (%)'};
0928            xlabel = 'Index in table';
0929            ylabel = 'Weight';
0930            set(handles.butt_load_labels,'Visible','off')
0931            set(handles.saveweight,'Visible','off')
0932        end
0933    end
0934    dat(:,1) = label;
0935    weights = handles.PRT.model(mi(m)).output.weight_ROI{handles.class}(:,ffi)*100;
0936    dat(:,2) = num2cell(weights);   
0937    
0938    % Fill the table with ROI size if ROIs
0939    if ~isempty(strfind(handles.PRT.model(mi(m)).input.machine.function,'MKL')) && ...
0940            handles.PRT.fs(fid).multkernelROI  %Multiple kernel learning on ROIs
0941        if isfield(handles.PRT.fs(fid).modality,'idfeat_img')&& ... % Get the indexes of each ROI in the image
0942                ~isempty(handles.PRT.fs(fid).modality(mids).idfeat_img)
0943            lc = [lc,{'ROI size (vox)'}];
0944            for i=1:length(handles.PRT.fas)
0945                if strcmpi(handles.PRT.fs(fid).modality(mids).mod_name,...
0946                        handles.PRT.fas(i).mod_name)
0947                    mid = i;
0948                end
0949            end
0950            idfeat = handles.PRT.fas(mid).idfeat_img;
0951            if isempty(handles.PRT.fs(fid).modality(mids).idfeat_fas) % get the 2nd level masking
0952                idfeat_fas = 1:length(idfeat);
0953            else
0954                idfeat_fas = handles.PRT.fs(fid).modality(mids).idfeat_fas;
0955            end
0956            handles.idfeat_roi = cell(length(handles.PRT.fs(fid).modality(mids).idfeat_img),1);
0957            for i = 1:length(handles.PRT.fs(fid).modality(mids).idfeat_img)
0958                dat(i,3) = {length(handles.PRT.fs(fid).modality(mids).idfeat_img{i})};
0959                handles.idfeat_roi{i} = idfeat(idfeat_fas(handles.PRT.fs(fid).modality(mids).idfeat_img{i}));
0960            end
0961        end
0962        set(handles.disp_regions,'Enable','on')
0963        flagmodMKL = 0;
0964    elseif isfield(handles.PRT.model(mi(m)).output,'weight_idfeatroi') &&... % Summarizing the weights for ROI
0965            ~isempty(handles.PRT.model(mi(m)).output.weight_idfeatroi) % Get the indexes of each ROI in the image
0966        lc = [lc,{'ROI size (vox)'}];
0967        handles.idfeat_roi = cell(length(handles.PRT.model(mi(m)).output.weight_idfeatroi{handles.class}),1);
0968        for i = 1:length(handles.PRT.model(mi(m)).output.weight_idfeatroi{handles.class})
0969            dat(i,3) = {length(handles.PRT.model(mi(m)).output.weight_idfeatroi{handles.class}{i})};
0970            handles.idfeat_roi{i} = handles.PRT.model(mi(m)).output.weight_idfeatroi{handles.class}{i};
0971        end
0972        set(handles.disp_regions,'Enable','on')
0973        flagmodMKL = 0;
0974    else % if MKL on modalities, do not fill third column and do not display weights per region
0975        set(handles.disp_regions,'Enable','off')
0976        flagmodMKL = 1;
0977    end 
0978    
0979    % Compute Expected Ranking for model
0980    w_all = handles.PRT.model(mi(m)).output.weight_ROI{handles.class}(:,1:handles.nfold)*100;
0981    %take 0 columns out of the computation
0982    mw = min(w_all);
0983    mxw = max(w_all);
0984    id0 = find(mw==mxw);
0985    id0 = id0(mw(id0)==0);
0986    id = 1:size(w_all,2);
0987    idtr = setdiff(id,id0);
0988    if isempty(idtr)   % if a modality has always 0 weights
0989        erwn=NaN*ones(length(num_roi),1);
0990    else
0991        w_all = w_all(:,idtr);
0992        %deal with NaNs
0993        [d1,d2]=sort(w_all,1,'descend');
0994        isn=find(isnan(w_all(:,1)));
0995        d3=1:length(isn);
0996        d4=length(isn)+1:size(d1,1);
0997        ihn=[d2(d4,:);d2(d3,:)];
0998        [d1,dwn]=sort(ihn);
0999        erwn=zeros(length(num_roi),1);
1000        for i=1:length(num_roi)
1001            for j=1:length(num_roi)
1002                tmp=length(find(dwn(i,1:end-1)==j));
1003                erwn(i)=erwn(i)+j*tmp;
1004            end
1005        end
1006        erwn=erwn/length(idtr);
1007    end
1008    
1009    dat = [dat, num2cell(erwn)]; 
1010    lc = [lc,{'Exp. Ranking'}];
1011    handles.dattable = dat;
1012    [vald,idwroi] = sort(weights,'descend');
1013    handles.sort_roi= idwroi;
1014 else
1015     % Cut window
1016     set(handles.disp_regions,'Enable','off')
1017 end
1018 
1019 if ~iscell(handles.PRT.model(mi(m)).output.weight_img)
1020     handles.PRT.model(mi(m)).output.weight_img={handles.PRT.model(mi(m)).output.weight_img};
1021 end
1022 
1023 % Select the image to display and check whether its ROI version exists
1024 if disp_vox
1025     fntl = handles.PRT.model(mi(m)).output.weight_img{handles.class};
1026     set(handles.disp_voxels,'Value',1)
1027     set(handles.disp_regions,'Value',0)
1028 elseif ~disp_vox && isfield(handles.PRT.model(mi(m)).output,'weight_ROI') &&... % chosen model has ROI values
1029        ~isempty(handles.PRT.model(mi(m)).output.weight_ROI{handles.class})
1030     fntl = ['ROI_',handles.PRT.model(mi(m)).output.weight_img{handles.class}];%get only first image for now
1031     set(handles.disp_voxels,'Value',0)
1032     set(handles.disp_regions,'Value',1)
1033 else
1034     beep
1035     disp('Weights per region selected, but no ROI_ image found')
1036     disp('Displaying image of weights per voxels')
1037     fntl = handles.PRT.model(mi(m)).output.weight_img{handles.class};
1038     set(handles.disp_voxels,'Value',1)
1039     set(handles.disp_regions,'Value',0)
1040 end
1041 
1042 % Call weightbutton to display the chosen image
1043 if exist([handles.prtdir,filesep,fntl,'.img'],'file') || ...
1044         exist([handles.prtdir,filesep,fntl],'file')
1045     [a,b] = fileparts(fntl);
1046     handles.wmap = [handles.prtdir,filesep,b,'.img'];
1047     V               = spm_vol(handles.wmap);
1048     handles.vols{1} = V;
1049     handles.noloadw = 1;
1050     handles.model_button = 0;
1051     handles.selectedcell = [];
1052     % Update handles structure
1053     guidata(hObject, handles);
1054     weightbutton_Callback(hObject, eventdata, handles);
1055 end
1056 
1057 % % Compute homogeneity of ROIs if MKL on ROIs or summarizing
1058 % if ~flagmodMKL && isfield(handles.PRT.model(mi(m)).output,'weight_ROI') &&... % chosen model has ROI values
1059 %        ~isempty(handles.PRT.model(mi(m)).output.weight_ROI) &&...
1060 %         isfield(handles,'wmap') && ~isempty(handles.wmap)
1061 %
1062 %     % Get homogeneity of each ROI in terms of sign from the image
1063 %     dat = handles.dattable;
1064 %     [vald,idwroi] = sort([dat{:,2}],'descend');
1065 %     hom = zeros(length(vald),handles.nfold+1);
1066 %     for f = 1:handles.nfold+1
1067 %         imtl = V(f);
1068 %         vv = spm_read_vols(imtl);
1069 %         for i = 1:length(vald) %for each ROI
1070 %             val = vv(handles.idfeat_roi{i});
1071 %             hom(i,f) = length(find(val>0))/length(val);
1072 %         end
1073 %         if length(unique(hom(:,f)))==1 % probably all weights to zero
1074 %             hom(:,f) = NaN;
1075 %         end
1076 %     end
1077 %    handles.hom_roi = hom;
1078 %    dat =[dat, num2cell(hom(:,end)*100)];
1079 %    lc = [lc,{'# Pos. (%)'}];
1080 % end
1081 
1082 % Fill modality table in the case of multiple modalities and multiple ROIs
1083 % (whether summarized or MKL)
1084 if isfield(handles.PRT.model(mi(m)).output,'weight_MOD') &&...
1085         ~isempty(handles.PRT.model(mi(m)).output.weight_MOD{handles.class}) && ...
1086         ~flagmodMKL
1087     datmod = cell(length(handles.nmods),3);
1088     datmod(:,1) = handles.nmods;
1089     wemod = zeros(length(handles.nmods),handles.nfold+1);
1090     for i=1:length(handles.nmods) % get all the modalities
1091         wemod(i,:) = [handles.PRT.model(mi(m)).output.weight_MOD{i}];
1092     end
1093     datmod(:,2) = num2cell(wemod(:,ffi)*100);
1094     % Compute Expected Ranking for modalities
1095     %take 0 columns out of the computation
1096     wem = wemod(:,1:handles.nfold);
1097     mw = min(wem);
1098     mxw = max(wem);
1099     id0 = find(mw==mxw);
1100     id0 = id0(mw(id0)==0);
1101     id = 1:size(wem,2);
1102     idtr = setdiff(id,id0);
1103     if isempty(idtr)   % if a modality has always 0 weights
1104        erwn2=NaN*ones(length(handles.nmods),1);
1105     else
1106        wem = wem(:,idtr);
1107        %deal with NaNs
1108        [d1,d2]=sort(wem,1,'descend');
1109        isn=find(isnan(wem(:,1)));
1110        d3=1:length(isn);
1111        d4=length(isn)+1:size(d1,1);
1112        ihn=[d2(d4,:);d2(d3,:)];
1113        [d1,dwn]=sort(ihn);
1114        erwn2=zeros(length(handles.nmods),1);
1115        for i=1:size(wem,1)
1116            for j=1:size(wem,1)
1117                tmp=length(find(dwn(i,1:end-1)==j));
1118                erwn2(i)=erwn2(i)+j*tmp;
1119            end
1120        end
1121        erwn2=erwn2/handles.nfold;
1122     end
1123    datmod(:,3) = num2cell(erwn2);
1124    [vald,idwmod] = sort(wemod(:,ffi),'descend');
1125    handles.sort_mod= idwmod;
1126 else
1127     datmod = [];
1128 end
1129 handles.datmod = datmod;  
1130 
1131 
1132 % Fill table and bar graph if needed
1133 if isfield(handles.PRT.model(mi(m)).output,'weight_ROI') &&... % chosen model has ROI or modality weight values
1134         ~isempty(handles.PRT.model(mi(m)).output.weight_ROI) &&...
1135         isfield(handles,'wmap') && ~isempty(handles.wmap)
1136     handles.dattable = dat;
1137     
1138     dat = dat(handles.sort_roi,:);
1139     set(handles.ROItable,'Data',dat);
1140     set(handles.ROItable,'ColumnEditable',false(1,length(lc)));
1141     set(handles.ROItable,'ColumnName',lc);
1142     set(handles.ROItable,'visible','on');
1143     
1144     %Bar graph to show decrease in ROI weights
1145     set(handles.axes1,'visible','on')
1146     bar(handles.axes1,weights(idwroi));
1147     set(get(handles.axes1,'XLabel'),'FontWeight','demi')
1148     set(get(handles.axes1,'XLabel'),'String',xlabel)
1149     set(get(handles.axes1,'YLabel'),'String',ylabel)
1150     set(get(handles.axes1,'YLabel'),'FontWeight','demi')
1151     
1152 
1153    if ~isempty(datmod)
1154       set(handles.modtable,'Visible','on')
1155       set(handles.modtable,'Enable','on')
1156       set(handles.modtable,'Data',datmod(handles.sort_mod,:))
1157       set(handles.modtable,'ColumnEditable',false(1,size(datmod,2)));
1158       set(handles.modtable,'ColumnName',{'Modality','Weight (%)','Exp. Ranking'});
1159    else
1160       set(handles.modtable,'Visible','off')
1161       set(handles.modtable,'Enable','off') 
1162    end    
1163    
1164 else
1165     cla(handles.axes1, 'reset');
1166     set(handles.ROItable,'visible','off');
1167     set(handles.axes1,'visible','off');
1168     set(handles.butt_load_labels,'visible','off');
1169     set(handles.saveweight,'Visible','off')
1170     set(handles.modtable,'Visible','off')
1171     set(handles.modtable,'Enable','off')
1172 end
1173 handles.flagmodMKL = flagmodMKL;
1174 handles.model_button = 0;
1175 guidata(hObject, handles);
1176 
1177 % --- Executes during object creation, after setting all properties.
1178 function imagemenu_CreateFcn(hObject, eventdata, handles)
1179 % hObject    handle to imagemenu (see GCBO)
1180 % eventdata  reserved - to be defined in a future version of MATLAB
1181 % handles    empty - handles not created until after all CreateFcns called
1182 
1183 % Hint: popupmenu controls usually have a white background on Windows.
1184 %       See ISPC and COMPUTER.
1185 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1186     set(hObject,'BackgroundColor','white');
1187 end
1188 
1189 
1190 function repedit_Callback(hObject, eventdata, handles)
1191 % hObject    handle to repedit (see GCBO)
1192 % eventdata  reserved - to be defined in a future version of MATLAB
1193 % handles    structure with handles and user data (see GUIDATA)
1194 
1195 % Hints: get(hObject,'String') returns contents of repedit as text
1196 %        str2double(get(hObject,'String')) returns contents of repedit as a double
1197 
1198 
1199 % --- Executes during object creation, after setting all properties.
1200 function repedit_CreateFcn(hObject, eventdata, handles)
1201 % hObject    handle to repedit (see GCBO)
1202 % eventdata  reserved - to be defined in a future version of MATLAB
1203 % handles    empty - handles not created until after all CreateFcns called
1204 
1205 % Hint: edit controls usually have a white background on Windows.
1206 %       See ISPC and COMPUTER.
1207 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1208     set(hObject,'BackgroundColor','white');
1209 end
1210 
1211 
1212 % Show crosshairs position
1213 % -------------------------------------------------------------------------
1214 function showpos()
1215 
1216 global st
1217 
1218 mp13 = st.handles.mmedit;
1219 mp14 = st.handles.vxedit;
1220 tx20 = st.handles.posintensitytext;
1221 
1222 set(mp13,'String',sprintf('%.1f %.1f %.1f',spm_orthviews('Pos')));
1223 pos = spm_orthviews('Pos',1);
1224 set(mp14,'String',sprintf('%.1f %.1f %.1f',pos));
1225 set(tx20,'String',sprintf('%g',spm_sample_vol(st.V,pos(1),pos(2),pos(3),st.hld)));
1226 
1227 cmap = get(gcf,'Colormap');
1228 if size(cmap,1)~=128
1229     spm_figure('Colormap','gray-jet');
1230 end
1231 
1232 
1233 % --- Executes on button press in resetbutton.
1234 function resetbutton_Callback(hObject, eventdata, handles)
1235 % hObject    handle to resetbutton (see GCBO)
1236 % eventdata  reserved - to be defined in a future version of MATLAB
1237 % handles    structure with handles and user data (see GUIDATA)
1238 spm_orthviews('Reset');
1239 if isfield(handles, 'wmap'), handles = rmfield(handles, 'wmap'); end
1240 if isfield(handles, 'aimg'), handles = rmfield(handles,'aimg'); end
1241 cla(handles.axes1, 'reset');
1242 set(handles.ROItable,'visible','off');
1243 set(handles.axes1,'visible','off');
1244 set(handles.butt_load_labels,'visible','off');
1245 set(handles.saveweight,'visible','off');
1246 set(handles.modtable,'Visible','off')
1247 set(handles.modtable,'Enable','off')
1248 handles.noloadw = 0;
1249 guidata(hObject, handles);
1250 
1251 % Save menu
1252 % -------------------------------------------------------------------------
1253 function savemenu_Callback(hObject, eventdata, handles)
1254 % hObject    handle to savemenu (see GCBO)
1255 % eventdata  reserved - to be defined in a future version of MATLAB
1256 % handles    structure with handles and user data (see GUIDATA)
1257 wd=cd;
1258 cd(handles.prtdir)
1259 [filename, pathname] = uiputfile( ...
1260     {'*.png','Portable Network Graphics (*.png)';...
1261     '*.jpeg','JPEG figure (*.jpeg)';...
1262     '*.tiff','Compressed TIFF figure (*.tiff)';...
1263     '*.fig','Matlab figure (*.fig)';...
1264     '*.pdf','Color PDF file (*.pdf)';...
1265     '*.epsc',  'Encapsulated PostScript (*.eps)'},...
1266     'Save figure as','.png');
1267 [a,b,c]=fileparts(filename);
1268 ext=['-d',c(2:end)];
1269 
1270 % Set the color of the different backgrounds and figure parameters to white
1271 cf=get(handles.figure1,'Color');
1272 set(handles.figure1,'Color',[1,1,1])
1273 aa=get(handles.figure1,'children');
1274 xc=[];
1275 for i=1:length(aa)
1276     if strcmpi(get(aa(i),'type'),'uipanel')
1277         try
1278             xc=[xc;get(aa(i),'BackgroundColor')];
1279             set(aa(i),'BackgroundColor',[1 1 1])
1280         end
1281         bb=get(aa(i),'children');
1282         if ~isempty(bb)
1283             for j=1:length(bb)
1284                 try
1285                     xc=[xc;get(bb(j),'BackgroundColor')];
1286                     set(bb(j),'BackgroundColor',[1 1 1])
1287                 end
1288                 if strcmpi(get(bb(j),'type'),'uipanel')
1289                     cc=get(bb(j),'children');
1290                     if ~isempty(cc)
1291                         for k=1:length(cc)
1292                             try
1293                                 xc=[xc;get(cc(k),'BackgroundColor')];
1294                                 set(cc(k),'BackgroundColor',[1 1 1])
1295                             end
1296                             if strcmpi(get(cc(k),'type'),'uipanel')
1297                                 dd=get(cc(k),'children');
1298                                 if ~isempty(dd)
1299                                     for l=1:length(dd)
1300                                         try
1301                                             xc=[xc;get(dd(l),'BackgroundColor')];
1302                                             set(dd(l),'BackgroundColor',[1 1 1])
1303                                         end
1304                                     end
1305                                 end
1306                             end
1307                         end
1308                     end
1309                 end
1310             end
1311         end
1312     end
1313     if ~strcmpi(get(aa(i),'type'),'uimenu')
1314         try
1315             xc=[xc;get(aa(i),'BackgroundColor')];
1316             set(aa(i),'BackgroundColor',[1 1 1])
1317         end
1318     end
1319 end
1320 
1321 print(handles.figure1,ext,[pathname,filesep,b],'-r500')
1322 
1323 % Set the color of the different backgrounds and figure parameters to white
1324 set(handles.figure1,'Color',cf)
1325 scount=1;
1326 for i=1:length(aa)
1327     if strcmpi(get(aa(i),'type'),'uipanel')
1328         try
1329             set(aa(i),'BackgroundColor',xc(scount,:))
1330             scount=scount+1;
1331         end
1332         bb=get(aa(i),'children');
1333         if ~isempty(bb)
1334             for j=1:length(bb)
1335                 try
1336                     set(bb(j),'BackgroundColor',xc(scount,:))
1337                     scount=scount+1;
1338                 end
1339                 if strcmpi(get(bb(j),'type'),'uipanel')
1340                     cc=get(bb(j),'children');
1341                     if ~isempty(cc)
1342                         for k=1:length(cc)
1343                             try
1344                                 set(cc(k),'BackgroundColor',xc(scount,:))
1345                                 scount=scount+1;
1346                             end
1347                             if strcmpi(get(cc(k),'type'),'uipanel')
1348                                 dd=get(cc(k),'children');
1349                                 if ~isempty(dd)
1350                                     for l=1:length(dd)
1351                                         try
1352                                             set(dd(l),'BackgroundColor',xc(scount,:))
1353                                             scount=scount+1;
1354                                         end
1355                                     end
1356                                 end
1357                             end
1358                         end
1359                     end
1360                 end
1361             end
1362         end
1363     elseif ~strcmpi(get(aa(i),'type'),'uimenu')
1364         try
1365             set(aa(i),'BackgroundColor',xc(scount,:))
1366             scount=scount+1;
1367         end
1368     end
1369 end
1370 
1371 cd(wd)
1372 
1373 % --- Executes on selection change in table if it is a ROI label.
1374 function disp_weights_CellSelectionCallback(hObject,eventdata,handles)
1375 % hObject    handle to foldmenu (see GCBO)
1376 % eventdata  reserved - to be defined in a future version of MATLAB
1377 % handles    structure with handles and user data (see GUIDATA)
1378 handles.selectedcell=eventdata.Indices;
1379 if ~isempty(handles.selectedcell) && handles.selectedcell(2)==1 && ...% ROI label selected
1380     ~handles.flagmodMKL
1381     weightbutton_Callback(hObject, eventdata, handles);
1382 else
1383     handles.selectedcell = [];
1384 end
1385 % Update handles structure
1386 guidata(hObject, handles);
1387 
1388 % --- Executes on selection change in foldmenu.
1389 function listbox1_Callback(hObject, eventdata, handles)
1390 % hObject    handle to foldmenu (see GCBO)
1391 % eventdata  reserved - to be defined in a future version of MATLAB
1392 % handles    structure with handles and user data (see GUIDATA)
1393 
1394 % Hints: contents = get(hObject,'String') returns foldmenu contents as cell array
1395 %        contents{get(hObject,'Value')} returns selected item from foldmenu
1396 
1397 
1398 % --- Executes during object creation, after setting all properties.
1399 function listbox1_CreateFcn(hObject, eventdata, handles)
1400 % hObject    handle to foldmenu (see GCBO)
1401 % eventdata  reserved - to be defined in a future version of MATLAB
1402 % handles    empty - handles not created until after all CreateFcns called
1403 
1404 % Hint: listbox controls usually have a white background on Windows.
1405 %       See ISPC and COMPUTER.
1406 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1407     set(hObject,'BackgroundColor','white');
1408 end
1409 
1410 % --- Executes on button press in butt_load_labels.
1411 function butt_load_labels_Callback(hObject, eventdata, handles)
1412 % hObject    handle to butt_load_labels (see GCBO)
1413 % eventdata  reserved - to be defined in a future version of MATLAB
1414 % handles    structure with handles and user data (see GUIDATA)
1415 mi = handles.mi;
1416 m = get(handles.classmenu,'Value');
1417 if m==0 % Mac weird error with popup menus
1418     m=1;
1419 end
1420 mim = get(handles.imagemenu,'Value');
1421 if mim==0
1422     mim=1;
1423 end
1424 fname=spm_select(1,'.mat','Select the file containing the names of the ROIs');
1425 if isempty(fname)
1426     disp('No file containing the names of the ROIs found, generic names used')
1427     handles.labels{mi(m)}{mim}=[];
1428 else
1429     load(fname)
1430     try
1431         handles.labels{mi(m)}{mim}=ROI_names;
1432     catch
1433         disp('No variable ROI_names found, generic names used')
1434     end
1435 end
1436 num_roi = handles.num_roi(:,mim);
1437 try
1438     label = handles.labels{mi(m)}{mim}(num_roi);
1439 catch
1440     if length(num_roi)==length(handles.labels{mi(m)}{mim})  % match between labels and number of regions
1441         label = handles.labels{mi(m)}{mim}(num_roi);
1442     elseif length(num_roi)==length(handles.labels{mi(m)}{mim})+1    %missing the 'others' region
1443         handles.labels{mi(m)}{mim} = [{'others'};handles.labels{mi(m)}{mim}];
1444         label = handles.labels{mi(m)}{mim}(num_roi);
1445     else
1446         warning('prt_ui_disp_weights:LabelsDoNotCorrespondtoROI',... % could not use file
1447             'Number of labels in .mat does not correspond to number of ROIs');
1448         label = [];
1449     end
1450 end
1451 if ~isempty(handles.labels{mi(m)}{mim}) && ~isempty(label)
1452     dat = handles.dattable;
1453     dat(:,1) = label;
1454     handles.dattable = dat;
1455     dat = dat(handles.sort_roi,:);
1456     set(handles.ROItable,'Data',dat);
1457     set(handles.ROItable,'visible','on');
1458     guidata(hObject, handles);
1459 end
1460 
1461 
1462 
1463 
1464 
1465 % --- Executes on button press in disp_voxels.
1466 function disp_voxels_Callback(hObject, eventdata, handles)
1467 % hObject    handle to disp_voxels (see GCBO)
1468 % eventdata  reserved - to be defined in a future version of MATLAB
1469 % handles    structure with handles and user data (see GUIDATA)
1470 
1471 % Hint: get(hObject,'Value') returns toggle state of disp_voxels
1472 
1473 % Get folds and model indexes
1474 m  = get(handles.classmenu,'Value');
1475 if m==0
1476     m=1;
1477 end
1478 mi = handles.mi;
1479 handles.nfold = length(handles.PRT.model(mi(m)).output.fold);
1480 ffi = get(handles.foldmenu,'Value')-1;
1481 if ffi == -1 % for Mac issues with popup menus
1482     ffi = 0;
1483 end
1484 if ffi==0 % for average
1485     ffi=handles.nfold+1;
1486 end
1487 
1488 % Select which image to display: weights per voxels or regions
1489 disp_vox = get(handles.disp_voxels,'Value');
1490 if disp_vox
1491     fntl = handles.PRT.model(mi(m)).output.weight_img{handles.class};
1492     set(handles.disp_regions,'Value',0);
1493 else
1494     fntl = ['ROI_',handles.PRT.model(mi(m)).output.weight_img{handles.class}];%get only first image for now
1495     set(handles.disp_regions,'Value',1);
1496     set(handles.disp_voxels,'Value',0);
1497 end
1498 
1499 %Load corresponding weight image if it exists
1500 if exist([handles.prtdir,filesep,fntl,'.img'],'file') || ...
1501         exist([handles.prtdir,filesep,fntl],'file')
1502     [a,b] = fileparts(fntl);
1503     handles.wmap = [handles.prtdir,filesep,b,'.img'];
1504     V               = spm_vol(handles.wmap);
1505     handles.vols{1} = V;
1506     handles.noloadw = 1;
1507     handles.model_button = 0;
1508     handles.selectedcell = [];
1509     % Update handles structure
1510     guidata(hObject, handles);
1511     weightbutton_Callback(hObject, eventdata, handles);
1512 else
1513     beep
1514     disp('Weight image does not exist for this model')
1515 end
1516 
1517     % Update handles structure
1518     guidata(hObject, handles);
1519 
1520 % --- Executes on button press in disp_regions.
1521 function disp_regions_Callback(hObject, eventdata, handles)
1522 % hObject    handle to disp_regions (see GCBO)
1523 % eventdata  reserved - to be defined in a future version of MATLAB
1524 % handles    structure with handles and user data (see GUIDATA)
1525 
1526 % Hint: get(hObject,'Value') returns toggle state of disp_regions
1527 % Get folds and model indexes
1528 m  = get(handles.classmenu,'Value');
1529 if m==0
1530     m=1;
1531 end
1532 mi = handles.mi;
1533 handles.nfold = length(handles.PRT.model(mi(m)).output.fold);
1534 ffi = get(handles.foldmenu,'Value')-1;
1535 if ffi == -1 % for Mac issues with popup menus
1536     ffi = 0;
1537 end
1538 if ffi==0 % for average
1539     ffi=handles.nfold+1;
1540 end
1541 
1542 % Select which image to display: weights per voxels or regions
1543 disp_reg = get(handles.disp_regions,'Value');
1544 if ~disp_reg
1545     fntl = handles.PRT.model(mi(m)).output.weight_img{handles.class};
1546     set(handles.disp_regions,'Value',0);
1547     set(handles.disp_voxels,'Value',1);
1548 else
1549     fntl = ['ROI_',handles.PRT.model(mi(m)).output.weight_img{handles.class}];%get only first image for now
1550     set(handles.disp_regions,'Value',1);
1551     set(handles.disp_voxels,'Value',0);
1552 end
1553 
1554 %Load corresponding weight image if it exists
1555 if exist([handles.prtdir,filesep,fntl,'.img'],'file') || ...
1556         exist([handles.prtdir,filesep,fntl],'file')
1557     [a,b] = fileparts(fntl);
1558     handles.wmap = [handles.prtdir,filesep,b,'.img'];
1559     V               = spm_vol(handles.wmap);
1560     handles.vols{1} = V;
1561     handles.noloadw = 1;
1562     handles.model_button = 0;
1563     handles.selectedcell = [];
1564     % Update handles structure
1565     guidata(hObject, handles);
1566     weightbutton_Callback(hObject, eventdata, handles);
1567 else
1568     beep
1569     disp('Weight image does not exist for this model')
1570 end
1571 
1572 % Update handles structure
1573 guidata(hObject, handles);
1574 
1575 
1576 
1577 % --- Executes when entered data in editable cell(s) in ROItable.
1578 function ROItable_CellEditCallback(hObject, eventdata, handles)
1579 % hObject    handle to ROItable (see GCBO)
1580 % eventdata  structure with the following fields (see UITABLE)
1581 %    Indices: row and column indices of the cell(s) edited
1582 %    PreviousData: previous data for the cell(s) edited
1583 %    EditData: string(s) entered by the user
1584 %    NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
1585 %    Error: error string when failed to convert EditData to appropriate value for Data
1586 % handles    structure with handles and user data (see GUIDATA)
1587 
1588 
1589 
1590 function edit7_Callback(hObject, eventdata, handles)
1591 % hObject    handle to edit7 (see GCBO)
1592 % eventdata  reserved - to be defined in a future version of MATLAB
1593 % handles    structure with handles and user data (see GUIDATA)
1594 
1595 % Hints: get(hObject,'String') returns contents of edit7 as text
1596 %        str2double(get(hObject,'String')) returns contents of edit7 as a double
1597 
1598 
1599 % --- Executes during object creation, after setting all properties.
1600 function edit7_CreateFcn(hObject, eventdata, handles)
1601 % hObject    handle to edit7 (see GCBO)
1602 % eventdata  reserved - to be defined in a future version of MATLAB
1603 % handles    empty - handles not created until after all CreateFcns called
1604 
1605 % Hint: edit controls usually have a white background on Windows.
1606 %       See ISPC and COMPUTER.
1607 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1608     set(hObject,'BackgroundColor','white');
1609 end
1610 
1611 
1612 % --- Executes on button press in saveweight.
1613 function saveweight_Callback(hObject, eventdata, handles)
1614 % hObject    handle to saveweight (see GCBO)
1615 % eventdata  reserved - to be defined in a future version of MATLAB
1616 % handles    structure with handles and user data (see GUIDATA)
1617 % chosen model has ROI values or weights per modality : create the table
1618 
1619 %If there are weights per region, then save the weightes for different
1620 %regisons
1621 mim = get(handles.imagemenu,'Value');
1622 if mim==0
1623     mim=1;
1624 end
1625 num_roi = handles.num_roi(:,mim);
1626 
1627 disp('Saving the sorted list of regions to text file.....>>');
1628 modelname = char(strcat(handles.mnames(get(handles.classmenu,'value')),'_RegionList.txt'));
1629 path = fileparts(handles.pathdir);
1630 weightname=fullfile(path,modelname);
1631 disp(weightname);
1632 fid=fopen(weightname,'w');
1633 fprintf(fid,'%23s %20s %20s %23s\r\n','"ROI Label"','"ROI weight (%)"','"ROI size (vox)"','"Exp. Ranking"');
1634 dat = handles.dattable;
1635 dat = dat(handles.sort_roi,:);
1636 for i = 1:size(num_roi)
1637     cellvalue= dat(i,:);
1638     fprintf(fid, '%22s %19f %20d %23f\r\n', cellvalue{:});
1639 end
1640 fclose(fid);
1641 disp('Save Done!');

Generated on Tue 10-Feb-2015 18:16:33 by m2html © 2005