-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprt_data_modality.m
More file actions
859 lines (799 loc) · 32.5 KB
/
Copy pathprt_data_modality.m
File metadata and controls
859 lines (799 loc) · 32.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
function varargout = prt_data_modality(varargin)
% PRT_DATA_MODALITY M-file for prt_data_modality.fig
%
% PRT_DATA_MODALITY, by itself, creates a new PRT_DATA_MODALITY or raises
% the existing singleton*.
%
% H = PRT_DATA_MODALITY returns the handle to a new PRT_DATA_MODALITY or
% the handle to the existing singleton*.
%
% PRT_DATA_MODALITY('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PRT_DATA_MODALITY.M with the given input arguments.
%
% PRT_DATA_MODALITY('Property','Value',...) creates a new PRT_DATA_MODALITY
% or raises the existing singleton*. Starting from the left, property value
% pairs are applied to the GUI before prt_data_modality_OpeningFcn gets called.
% An unrecognized property name or invalid value makes property application
% stop. All inputs are passed to prt_data_modality_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
% Written by J.Schrouff
% $Id$
% Edit the above text to modify the response to help prt_data_modality
% Last Modified by GUIDE v2.5 31-Jul-2018 11:19:33
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @prt_data_modality_OpeningFcn, ...
'gui_OutputFcn', @prt_data_modality_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before prt_data_modality is made visible.
function prt_data_modality_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to prt_data_modality (see VARARGIN)
% Choose default command line output for prt_data_modality
handles.output = hObject;
%if window already exists, just put it as the current figure
Tag='DDmod';
F = findall(allchild(0),'Flat','Tag',Tag);
if length(F) > 1
% Multiple Graphics windows - close all but most recent
close(F(2:end))
F = F(1);
uistack(F,'top')
elseif length(F)==1
uistack(F,'top')
else
set(handles.figure1,'Tag',Tag)
set(handles.figure1,'Name','PRoNTo :: Specify modality')
%set size of the window, taking screen resolution and platform into account
S0= spm('WinSize','0',1); %-Screen size (of the current monitor)
if ispc
PF='MS Sans Serif';
else
PF= spm_platform('fonts'); %-Font names (for this platform)
PF=PF.helvetica;
end
tmp = [S0(3)/1280 (S0(4))/800];
ratio=min(tmp)*[1 1 1 1];
FS = 1 + 0.85*(min(ratio)-1); %factor to scale the fonts
x=get(handles.figure1,'Position');
set(handles.figure1,'DefaultTextFontSize',FS*8,...
'DefaultUicontrolFontSize',FS*8,...
'DefaultTextFontName',PF,...
'DefaultAxesFontName',PF,...
'DefaultUicontrolFontName',PF)
set(handles.figure1,'Position',ratio.*x)
set(handles.figure1,'Resize','on')
% Choose the color of the different backgrounds and figure parameters
color=prt_get_defaults('color');
set(handles.figure1,'Color',color.bg1)
aa=get(handles.figure1,'children');
for i=1:length(aa)
if strcmpi(get(aa(i),'type'),'uipanel')
set(aa(i),'BackgroundColor',color.bg2)
bb=get(aa(i),'children');
if ~isempty(bb)
for j=1:length(bb)
if ~isempty(find(strcmpi(get(bb(j),'Style'),{'text',...
'radiobutton','checkbox'})))
set(bb(j),'BackgroundColor',color.bg2)
elseif ~isempty(find(strcmpi(get(bb(j),'Style'),'pushbutton')))
set(bb(j),'BackgroundColor',color.fr)
end
set(bb(j),'FontUnits','pixel')
xf=get(bb(j),'FontSize');
set(bb(j),'FontSize',ceil(FS*xf),'FontName',PF,...
'FontUnits','normalized','Units','normalized')
end
end
else
if ~isempty(find(strcmpi(get(aa(i),'Style'),{'text',...
'radiobutton','checkbox','listbox'})))
set(aa(i),'BackgroundColor',color.bg1)
elseif ~isempty(find(strcmpi(get(aa(i),'Style'),'pushbutton')))
set(aa(i),'BackgroundColor',color.fr)
end
end
set(aa(i),'FontUnits','pixel')
xf=get(aa(i),'FontSize');
if ispc
set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
'FontUnits','normalized','Units','normalized')
else
set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
'Units','normalized')
end
end
handles.mod=[];
handles.mod.detrend=0;
handles.mod.design=0;
handles.mod.scans=[];
handles.mod.name={};
handles.mod.covar=[];
handles.mod.rt_subj=[];
handles.mod.type = 'nifti';
handles.subj1=0;
set(handles.design_menu,...
'String',{'No design','Specify design','Load SPM.mat'},...
'Value',1);
set(handles.target_menu,...
'String',{'Specify targets','No targets'},...
'Value',2);
set(handles.type,...
'String',{'nifti','MEEG','.mat'},...
'Value',1);
if ~isempty(varargin) && strcmpi(varargin{1},'UserData')
%Particular options if you select by 'scans'
if ~isempty(varargin{2}{2})
if ~isempty(varargin{2}{3}) % Review or modify existing modality
openmod = 1;
set(handles.modname,'Enable','off')
else % Create new modality
openmod = 0;
set(handles.modname,'Enable','on')
end
handles.scans =strcmpi(varargin{2}{2}.subj_name,'Samples');
if strcmpi(varargin{2}{2}.subj_name,'Samples') || ...
(isfield(varargin{2}{2},'modality') && ...
(openmod && ~isstruct(varargin{2}{2}.modality(varargin{2}{3}).design)) && ...
(openmod && isempty(varargin{2}{2}.modality(varargin{2}{3}).design))) %No design, One image per subject
set(handles.design_menu,'Enable','off')
set(handles.target_menu,'Enable','on')
set(handles.edit_covar,'Enable','on')
set(handles.edit_covar,'Visible','on')
set(handles.text7,'Visible','on') % Covariates
else % When more than one image per subject (i.e. design), only regression targets and covariates within trials
set(handles.target_menu,'Enable','off')
set(handles.edit_covar,'Enable','off')
set(handles.edit_covar,'Visible','off')
set(handles.text7,'Visible','off')
end
else
set(handles.design_menu,'Enable','on')
set(handles.edit_covar,'Enable','off')
set(handles.edit_covar,'Visible','off')
set(handles.text7,'Visible','off')
set(handles.target_menu,'Enable','off')
end
if ~isempty(varargin{2}{2}) && isfield(varargin{2}{2},'modality') && ...
~isempty(varargin{2}{2}.modality)
handles.subjmod={varargin{2}{2}.modality(:).mod_name};
if length(varargin{2})>=3 && ~isempty(varargin{2}{3})
nlist=varargin{2}{1};
modsel=varargin{2}{2}.modality(varargin{2}{3});
valsel=find(strcmpi(modsel.mod_name,nlist));
set(handles.modname,'String',cellstr(nlist)); % [UPDATE v3.1 - R2025a] ensure cell array
set(handles.modname,'Value',max(1,valsel(1))); % [UPDATE v3.1 - R2025a] ensure scalar Value
handles.mod.design=modsel.design;
if ~isempty(modsel.design)
if ~isstruct(modsel.design) && modsel.design== 0
set(handles.design_menu,'Value',1)
handles.desnmenu = 3;
else
set(handles.design_menu,'Value',2)
handles.desnmenu = 2;
end
end
handles.mod.scans=modsel.scans;
handles.mod.name=modsel.mod_name;
handles.mod.covar=modsel.covar;
if ~isempty(modsel.covar)
set(handles.edit_covar,'Enable','on')
set(handles.edit_covar,'Visible','on')
set(handles.text7,'Visible','on')
if size(modsel.covar,1)==1 %Review numbers for only one subject
set(handles.edit_covar,'String',num2str(modsel.covar))
else
set(handles.edit_covar,'String','Entered','FontAngle','Italic')
end
end
handles.mod.rt_subj=modsel.rt_subj;
if ~isempty(modsel.rt_subj)
set(handles.target_menu,'Enable','on')
set(handles.target_menu,'Value',1)
end
if isfield(modsel,'type')
if strcmpi(modsel.type,'MEEG')
set(handles.type,'Value',2)
set(handles.design_menu,...
'String',{'Events in file'},...
'Value',1);
else
if strcmpi(modsel.type,'.mat')
set(handles.type,'Value',3)
set(handles.design_menu,'Enable','on')
else
set(handles.type,'Value',1)
end
end
handles.mod.type = modsel.type;
else
set(handles.type,'Value',1)
end
set(handles.modname,'Enable','off')
else
nlist=[varargin{2}{1}, {'Enter new'}];
set(handles.modname,'String',cellstr(nlist),'Value',max(1,length(nlist))); % [UPDATE v3.1 - R2025a]
end
else
nlist=[varargin{2}{1}, {'Enter new'}];
set(handles.modname,'String',cellstr(nlist),'Value',max(1,length(nlist))); % [UPDATE v3.1 - R2025a]
handles.subjmod={};
end
else
nlist={'Enter new'};
handles.subjmod={};
set(handles.modname,'String',cellstr(nlist),'Value',1); % [UPDATE v3.1 - R2025a] ensure cell array
end
if length(varargin{2})>=4 && ~isempty(varargin{2}{4})
handles.subj1=varargin{2}{4};
end
if length(varargin{2})==5 && ~isempty(varargin{2}{5})
handles.PRT=varargin{2}{5};
end
warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
end
% Update handles structure
guidata(hObject, handles);
% %UIWAIT makes prt_data_modality wait for user response (see UIRESUME)
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = prt_data_modality_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
if isfield(handles,'output') && ~isempty(handles.output)
varargout{1} = handles.output;
else
varargout{1}=[];
end
% The figure can be deleted now
if isfield(handles,'figure1')
delete(handles.figure1);
end
% --- Executes on selection change in modname.
function modname_Callback(hObject, eventdata, handles)
% hObject handle to modname (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns modname contents as cell array
% contents{get(hObject,'Value')} returns selected item from modname
warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
list=get(handles.modname,'String');
%handle particular bug with matlab(7.10.0499) and mac (OSX 10.6.4)
if length(list)==1
set(handles.modname,'Value',1)
end
if any(strfind(list{get(handles.modname,'Value')}, 'Enter'))
modname=prt_text_input('Title','Enter modality name');
if isnumeric(modname)
return
end
if ~any(strcmpi(list,modname))
nlist=[list;{modname}];
else
beep
disp('This modality has already been set for the selected subject')
set(handles.modname,'String',cellstr(list)); % [UPDATE v3.1 - R2025a] ensure cell array
valall=strfind(list,'Enter');
for i=1:length(valall)
if ~isempty(valall{i})
val=i;
break
end
end
set(handles.modname,'Value',max(1,val(1))); % [UPDATE v3.1 - R2025a] ensure scalar Value
return
end
set(handles.modname,'String',cellstr(nlist)); % [UPDATE v3.1 - R2025a] ensure cell array
set(handles.modname,'Value',max(1,length(nlist))); % [UPDATE v3.1 - R2025a] ensure scalar Value
else
modname=list{get(handles.modname,'Value')};
if ~isempty(handles.subjmod)
if any(strcmpi(handles.subjmod,modname))
set(handles.modname,'String',cellstr(list)); % [UPDATE v3.1 - R2025a] ensure cell array
valall=strfind(list,'Enter');
if length(valall)==1 && isempty(valall{1}) %case of reviewing the modality
val=1;
set(handles.modname,'Value',max(1,val(1))); % [UPDATE v3.1 - R2025a] ensure scalar Value
else %user tries to give a name he already used
beep
disp('This modality has already been set for the selected subject')
for i=1:length(valall)
if ~isempty(valall{i})
val=i;
break
end
end
set(handles.modname,'Value',max(1,val(1))); % [UPDATE v3.1 - R2025a] ensure scalar Value
return
end
end
end
end
%if a subject was previously entered in this modality, extract info
if isstruct(handles.subj1)
if any(strcmpi(modname, {handles.subj1(:).mod_name}))
handles.indmods1=find(strcmpi(modname, {handles.subj1(:).mod_name}));
% Automatically set data type and design options
type = handles.subj1(handles.indmods1).type;
if strcmpi(type,'MEEG')
set(handles.type,'Value',2)
set(handles.design_menu,...
'String',{'Events in file'},...
'Value',1);
else
if strcmpi(type,'.mat')
set(handles.type,'Value',3)
set(handles.design_menu,...
'String',{'No design','Specify design'},...
'Value',1);
else
set(handles.type,'Value',1)
set(handles.design_menu,...
'String',{'No design','Specify design','Load SPM.mat'},...
'Value',1);
end
end
handles.mod.type = type;
% Allow to replicate subject 1 design
list=get(handles.design_menu,'String');
list=[list;{'Replicate design of subject 1'}];
set(handles.design_menu,'String',cellstr(list)); % [UPDATE v3.1 - R2025a] ensure cell array
end
end
handles.mod.name=modname;
% Update handles structure
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function modname_CreateFcn(hObject, eventdata, handles)
% hObject handle to modname (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in design_menu.
function design_menu_Callback(hObject, eventdata, handles)
% hObject handle to design_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns design_menu contents as cell array
% contents{get(hObject,'Value')} returns selected item from design_menu
choice=get(handles.design_menu,'Value');
choice=choice(1); % [UPDATE v3.1 - R2025a] ensure scalar Value
%Mac and Matlab versions strange things with popup menus
if choice==0
choice=handles.desnmenu;
end
list = get(handles.design_menu,'String');
chosen = list{choice};
switch chosen
case 'Load SPM.mat' % for nifti only
desn=spm_select(1,'mat','Select SPM.mat file',[],[],'SPM.mat');
try
load(desn);
catch
beep
disp('Can not load SPM.mat file');
return
end
conds=struct();
list={};
for sspm=1:length(SPM.Sess) % Gather SPM.mat fields
ncond = length(SPM.Sess(sspm).U);
for c = 1:ncond
if sspm==1 %set the conditions
conds(c).cond_name = SPM.Sess(sspm).U(c).name{1};
list=[list, {conds(c).cond_name}];
conds(c).onsets = SPM.Sess(sspm).U(c).ons;
if length(SPM.Sess(sspm).U(c).dur)==1
conds(c).durations=repmat(SPM.Sess(sspm).U(c).dur,...
numel(conds(c).onsets),1);
else
conds(c).durations = SPM.Sess(sspm).U(c).dur;
end
indcond=ncond;
else %for other sessions, look if the conditions are the same
name_cond=SPM.Sess(sspm).U(c).name{1};
itoadd=find(strcmpi(name_cond,list));
if isempty(itoadd) % if not, then add condition
indcond=indcond+1;
conds(indcond).cond_name = SPM.Sess(sspm).U(c).name{1};
conds(indcond).onsets = SPM.Sess(sspm).U(c).ons;
if length(SPM.Sess(sspm).U(c).dur)==1
conds(indcond).durations=repmat(SPM.Sess(sspm).U(c).dur,...
numel(conds(indcond).onsets),1);
else
conds(indcond).durations = SPM.Sess(sspm).U(c).dur;
end
list=[list, {name_cond}];
else %if yes, then add the onsets
conds(itoadd).onsets = [conds(itoadd).onsets;SPM.Sess(sspm).U(c).ons];
if length(SPM.Sess(sspm).U(c).dur)==1
tmp=repmat(SPM.Sess(sspm).U(c).dur,...
numel(SPM.Sess(sspm).U(c).ons),1);
else
tmp = SPM.Sess(sspm).U(c).dur;
end
conds(itoadd).durations = [conds(itoadd).durations;tmp];
end
end
end
end
def=prt_get_defaults('datad'); % HRF parameters only for nifti
if isfield(handles.PRT.group,'hrfoverlap')
overl=handles.PRT.group.hrfoverlap;
else
overl=def.hrfw;
end
if isfield(handles.PRT.group,'hrfdelay')
del=handles.PRT.group.hrfdelay;
else
del=def.hrfd;
end
if length(unique([SPM.xX.K(:).RT])) ~=1
beep
disp('Differents TR found in SPM.mat, please separate sessions')
return
else
RT = SPM.xX.K(:).RT;
end
if strcmpi(SPM.xBF.UNITS,'scans') %units, TR or seconds
units=0;
else
units=1;
end
%check that TR is the same for all sessions
desn=prt_check_design(conds,RT,units,overl,del);
desn.covar = [];
case 'Specify design'
if isstruct(handles.mod.design)
desn=prt_data_conditions('UserData',{handles.mod.design,handles.PRT,0});
else
desn=prt_data_conditions;
end
case 'No design'
desn=[];
if size(handles.mod.scans,1)==1 %If no design and one image, can enter covariates and RT
set(handles.design_menu,'Value')
set(handles.target_menu,'Enable','on')
set(handles.edit_covar,'Enable','on')
set(handles.edit_covar,'Visible','on')
set(handles.text7,'Visible','on')
elseif ~handles.scans && size(handles.mod.scans,1)>1
set(handles.target_menu,'Enable','off')
set(handles.edit_covar,'Enable','off')
set(handles.edit_covar,'Visible','off')
set(handles.text7,'Visible','off')
handles.mod.covar=[];
handles.mod.rt_subj=[];
end
case 'Replicate design of subject 1'
desn=handles.subj1(handles.indmods1).design;
case 'Events in file' % For MEEG only
if isempty(handles.mod.scans)
beep
disp('Select .mat for subject first')
return
elseif size(handles.mod.scans,1)>1
beep
disp('Select only one file per modality for MEEG')
return
end
if ~isstruct(handles.mod.design)
D = spm_eeg_load(handles.mod.scans(1,:));
desn = prt_get_design_MEEG(D);
desn.covar = [];
handles.mod.design=desn;
end
desn=prt_data_conditions('UserData',{handles.mod.design,handles.PRT,1});
end
handles.mod.design=desn;
if isfield(desn,'covar') && ~isempty(desn.covar)
set(handles.edit_covar,'String','Entered');
set(handles.edit_covar,'Visible','on');
set(handles.text7, 'Visible','on')
end
if choice ~= 3
set(handles.target_menu,'Enable','off')
set(handles.edit_covar,'Enable','off')
set(handles.edit_covar,'Visible','off')
set(handles.text7,'Visible','off')
handles.mod.covar=[];
handles.mod.rt_subj=[];
end
% Update handles structure
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function design_menu_CreateFcn(hObject, eventdata, handles)
% hObject handle to design_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in getfiles.
function getfiles_Callback(hObject, eventdata, handles)
% hObject handle to getfiles (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isempty(handles.mod.scans)
sel=cellstr(handles.mod.scans);
else
sel=[];
end
typ = get(handles.type,'Value');
desn=[];
if typ>1 % either MEEG or .mat with data matrix (v3.1)
% [UPDATE v3.1 - R2025a] spm_select uses cfg_getfile which has a
% listbox scalar bug in R2025a. Wrap in try/catch and fall back to
% uigetfile if spm_select fails.
try
[t, status]=spm_select([1 Inf],'mat','Select files for the modality',sel);
catch
[fname, fpath] = uigetfile('*.mat','Select files for the modality','MultiSelect','on');
if isequal(fname,0)
t = ''; status = 0;
else
if ischar(fname); fname = {fname}; end
t = char(cellfun(@(f) fullfile(fpath,f), fname, 'UniformOutput', false));
status = 1;
end
end
if typ==2 %MEEG, load events in file
if isempty(t)
beep
disp('Select .mat for subject first')
return
elseif size(t,1)>1
beep
disp('Select only one file per modality for MEEG')
return
end
if ~isstruct(handles.mod.design)
D = spm_eeg_load(t(1,:));
desn = prt_get_design_MEEG(D);
desn.covar = [];
handles.mod.design=desn;
end
end
handles.mod.design=desn;
if isfield(desn,'covar') && ~isempty(desn.covar)
set(handles.edit_covar,'String','Entered');
set(handles.edit_covar,'Visible','on');
set(handles.text7, 'Visible','on')
end
else
% [UPDATE v3.1 - R2025a] spm_select uses cfg_getfile which has a
% listbox scalar bug in R2025a. Wrap in try/catch and fall back to
% uigetfile if spm_select fails.
try
[t,status]=spm_select([1 Inf],'image','Select files for the modality',sel);
catch
[fname, fpath] = uigetfile({'*.img;*.nii','Image files (*.img,*.nii)'},...
'Select files for the modality','MultiSelect','on');
if isequal(fname,0)
t = ''; status = 0;
else
if ischar(fname); fname = {fname}; end
t = char(cellfun(@(f) fullfile(fpath,f), fname, 'UniformOutput', false));
status = 1;
end
end
end
if status
handles.mod.scans=t;
else
handles.mod.scans=sel;
end
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in type.
function type_Callback(hObject, eventdata, handles)
% hObject handle to type (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of type
val = get(handles.type,'Value');
typ = get(handles.type,'String');
if val==0
val=1;
set(handles.type,'Value',val(1)) % [UPDATE v3.1 - R2025a] ensure scalar Value
end
if val==2
set(handles.design_menu,...
'String',{'Events in file'},...
'Value',1);
else
if val==1
set(handles.design_menu,...
'String',{'No design','Specify design','Load SPM.mat'},...
'Value',1);
else
set(handles.design_menu,...
'String',{'No design','Specify design'},...
'Value',1);
end
if isstruct(handles.subj1)
list=get(handles.modname,'String');
modname=list{get(handles.modname,'Value')};
if any(strcmpi(modname, {handles.subj1(:).mod_name}))
handles.indmods1=find(strcmpi(modname, {handles.subj1(:).mod_name}));
list=get(handles.design_menu,'String');
list=[list;{'Replicate design of subject 1'}];
set(handles.design_menu,'String',cellstr(list)); % [UPDATE v3.1 - R2025a] ensure cell array
end
end
end
handles.mod.type = typ{val};
% Update handles structure
guidata(hObject, handles);
% --- Executes on selection change in target_menu.
function target_menu_Callback(hObject, eventdata, handles)
% hObject handle to target_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns target_menu contents as cell array
% contents{get(hObject,'Value')} returns selected item from target_menu
choice=get(handles.target_menu,'Value');
choice=choice(1); % [UPDATE v3.1 - R2025a] ensure scalar Value
%Mac and Matlab versions strange things with popup menus
if choice==0
choice=2;
end
switch choice
case 2
rte = [];
case 1
if isstruct(handles.mod.rt_subj)
rte=prt_data_targets('UserData',{handles.mod.rt_subj,handles.PRT,0});
else
rte=prt_data_targets;
end
end
handles.mod.rt_subj=rte;
% Update handles structure
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function target_menu_CreateFcn(hObject, eventdata, handles)
% hObject handle to target_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_covar_Callback(hObject, eventdata, handles)
% hObject handle to edit_covar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_covar as text
% str2double(get(hObject,'String')) returns contents of edit_covar as a double
%first option of loading: writing the values
rt=get(handles.edit_covar,'String');
if isempty(rt)
return
end
try
eval(['rte=[',rt,'];'])
catch
try
load(char(rt));
catch
beep
disp('Could not load file or read the covariate values')
disp('Please enter either a .mat file name or enter the values')
return
end
if ~exist('R','var')
beep
sprintf('Covariates file must contain ''R'' variable! ')
disp('Please correct!')
return
else
rte=R;
end
end
handles.mod.covar=rte;
% Update handles structure
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function edit_covar_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_covar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in okbutton.
function okbutton_Callback(hObject, eventdata, handles)
% hObject handle to okbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%check that the files were selected
if isempty(handles.mod.scans)
beep
disp('Please, select the files before returning')
return
end
%check that the regression targets have the same number of elements as the
%number of scans or as the number of events in design
if ~isempty(handles.mod.rt_subj)
szrt=length(handles.mod.rt_subj(1).tar); %prt_data_targets already check all targets have the same number of values
if size(handles.mod.scans,1)~=szrt
beep
disp('Number of regression targets must be the number of files selected! ')
disp('Please correct!')
return
end
if ~handles.scans && size(handles.mod.scans,1)>1
beep
disp('Regression targets can only be entered if one image per subject! ')
disp('Please correct!')
return
end
end
%check that the covariates have the same number of elements as the
%number of scans
if ~isempty(handles.mod.covar)
szrt=size(handles.mod.covar);
nsc = size(handles.mod.scans,1);
ins = find(szrt == nsc);
if isempty(ins)
beep
disp('Number of covariates must be the number of files selected! ')
disp('Please correct!')
return
else
if ~handles.scans && size(handles.mod.scans,1)>1
beep
disp('Covariates can only be entered if one image per subject! ')
disp('Please correct!')
return
end
if ins~=1 %not the first dimension
handles.mod.covar = handles.mod.covar';
end
end
end
modprop=handles.mod;
handles.output=modprop;
% Update handles structure
guidata(hObject, handles);
uiresume(handles.figure1);
% --- Executes on button press in cancelbutton.
function cancelbutton_Callback(hObject, eventdata, handles)
% hObject handle to cancelbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
uiresume(handles.figure1);