├── README.md ├── Results_main.m ├── Sample Data ├── Language Task Additional 100 sub │ ├── Analysis │ │ └── EmptyFile.txt │ ├── Data Pos │ │ ├── 300618 │ │ │ └── EmptyFile.txt │ │ └── 300719 │ │ │ └── EmptyFile.txt │ ├── Preprocessed Data │ │ └── EmptyFile.txt │ ├── Raw Data │ │ ├── 300618 │ │ │ └── EmptyFile.txt │ │ └── 300719 │ │ │ └── EmptyFile.txt │ ├── Spiral Detected │ │ └── EmptyFile.txt │ └── TaskLabel │ │ └── EmptyFile.txt ├── Language Task Original 100 sub │ ├── Analysis │ │ └── EmptyFile.txt │ ├── Data Pos │ │ ├── 100206 │ │ │ └── L.flat.32k_fs_LR.surf.gii │ │ └── 100610 │ │ │ └── L.flat.32k_fs_LR.surf.gii │ ├── Preprocessed Data │ │ └── EmptyFile.txt │ ├── Raw Data │ │ ├── 300618 │ │ │ └── EmptyFile.txt │ │ └── 300719 │ │ │ └── EmptyFile.txt │ ├── Spiral Detected │ │ └── EmptyFile.txt │ └── TaskLabel │ │ └── EmptyFile.txt ├── Resting │ ├── Analysis │ │ └── EmptyFile.txt │ ├── Data Pos │ │ ├── 100206 │ │ │ └── L.flat.32k_fs_LR.surf.gii │ │ └── 100610 │ │ │ └── L.flat.32k_fs_LR.surf.gii │ ├── Preprocessed Data │ │ └── EmptyFile.txt │ ├── Raw Data │ │ ├── 100206 │ │ │ └── EmptyFile.txt │ │ └── 100610 │ │ │ └── EmptyFile.txt │ └── Spiral Detected │ │ └── EmptyFile.txt ├── Working Memory Task │ ├── Analysis │ │ └── L.flat.32k_fs_LR.surf.gii │ ├── Data Pos │ │ ├── 100206 │ │ │ └── L.flat.32k_fs_LR.surf.gii │ │ └── 100610 │ │ │ └── L.flat.32k_fs_LR.surf.gii │ ├── Preprocessed Data │ │ └── L.flat.32k_fs_LR.surf.gii │ ├── Raw Data │ │ ├── 100206 │ │ │ └── L.flat.32k_fs_LR.surf.gii │ │ └── 100610 │ │ │ └── L.flat.32k_fs_LR.surf.gii │ ├── Spiral Detected │ │ └── L.flat.32k_fs_LR.surf.gii │ └── TaskLabel │ │ └── L.flat.32k_fs_LR.surf.gii ├── parcellation_template.mat └── parcellation_template7.mat ├── Sub-function ├── PCA.m ├── PhaseVectorAngle_local_classifier.m ├── Preprocessing_main.m ├── TaskLabel_Extract.m ├── anglesubtract.m ├── bandpa_fMRI.m ├── cifti-matlab-master │ ├── @gifti │ │ ├── Contents.m │ │ ├── display.m │ │ ├── export.m │ │ ├── fieldnames.m │ │ ├── gifti.m │ │ ├── isfield.m │ │ ├── plot.m │ │ ├── private │ │ │ ├── Makefile │ │ │ ├── Makefile.var │ │ │ ├── base64decode.m │ │ │ ├── base64encode.m │ │ │ ├── getdict.m │ │ │ ├── isintent.m │ │ │ ├── miniz.c │ │ │ ├── mvtk_write.m │ │ │ ├── read_freesurfer_file.m │ │ │ ├── read_gifti_file_standalone.m │ │ │ ├── xml_parser.m │ │ │ ├── zstream.c │ │ │ └── zstream.m │ │ ├── save.m │ │ ├── saveas.m │ │ ├── struct.m │ │ ├── subsasgn.m │ │ └── subsref.m │ ├── @xmltree │ │ ├── Contents.m │ │ ├── add.m │ │ ├── attributes.m │ │ ├── branch.m │ │ ├── char.m │ │ ├── children.m │ │ ├── convert.m │ │ ├── copy.m │ │ ├── delete.m │ │ ├── display.m │ │ ├── editor.m │ │ ├── find.m │ │ ├── flush.m │ │ ├── get.m │ │ ├── getfilename.m │ │ ├── isfield.m │ │ ├── length.m │ │ ├── move.m │ │ ├── parent.m │ │ ├── private │ │ │ ├── xml_findstr.c │ │ │ ├── xml_findstr.m │ │ │ ├── xml_findstr.mexa64 │ │ │ ├── xml_findstr.mexglx │ │ │ ├── xml_findstr.mexmaci │ │ │ ├── xml_findstr.mexmaci64 │ │ │ ├── xml_findstr.mexw32 │ │ │ ├── xml_findstr.mexw64 │ │ │ └── xml_parser.m │ │ ├── root.m │ │ ├── save.m │ │ ├── set.m │ │ ├── setfilename.m │ │ └── xmltree.m │ ├── GPL │ ├── LICENSE.fieldtrip │ ├── LICENSE.gifti │ ├── LICENSE.xmltree │ ├── README.md │ ├── VERSION │ ├── documentation │ │ ├── CIFTI-2_Appendix_FINAL_1March2014.pdf │ │ └── CIFTI-2_Main_FINAL_1March2014.pdf │ ├── emptyfile.txt │ ├── ft_read_cifti.m │ ├── ft_write_cifti.m │ ├── package.sh │ └── private │ │ ├── copyfields.m │ │ ├── fetch_url.m │ │ ├── filetype_check_extension.m │ │ ├── filetype_check_header.m │ │ ├── filetype_check_uri.m │ │ ├── find_outermost_boundary.m │ │ ├── fixname.m │ │ ├── fixpos.m │ │ ├── ft_convert_units.m │ │ ├── ft_datatype.m │ │ ├── ft_datatype_sens.m │ │ ├── ft_estimate_units.m │ │ ├── ft_filetype.m │ │ ├── ft_getopt.m │ │ ├── ft_getopt.mexa64 │ │ ├── ft_getopt.mexglx │ │ ├── ft_getopt.mexmaci │ │ ├── ft_getopt.mexmaci64 │ │ ├── ft_getopt.mexw32 │ │ ├── ft_getopt.mexw64 │ │ ├── ft_hastoolbox.m │ │ ├── ft_read_header.m │ │ ├── ft_read_headshape.m │ │ ├── ft_read_mri.m │ │ ├── ft_read_sens.m │ │ ├── ft_read_vol.m │ │ ├── ft_scalingfactor.m │ │ ├── ft_senstype.m │ │ ├── ft_struct2double.m │ │ ├── ft_voltype.m │ │ ├── ft_warning.m │ │ ├── ft_warp_apply.m │ │ ├── ft_write_headshape.m │ │ ├── getdimord.m │ │ ├── getdimsiz.m │ │ ├── hasyokogawa.m │ │ ├── individual2sn.m │ │ ├── inflate_file.m │ │ ├── istrue.m │ │ ├── keepfields.m │ │ ├── ndgrid.m │ │ ├── pos2transform.m │ │ ├── read_asa.m │ │ ├── read_besa_sfp.m │ │ ├── read_bti_hs.m │ │ ├── read_bv_srf.m │ │ ├── read_caret_spec.m │ │ ├── read_ctf_hc.m │ │ ├── read_ctf_pos.m │ │ ├── read_ctf_shape.m │ │ ├── read_neuromag_hc.m │ │ ├── read_nifti2_hdr.m │ │ ├── read_off.m │ │ ├── read_ply.m │ │ ├── read_polhemus_fil.m │ │ ├── read_stl.m │ │ ├── read_vtk.m │ │ ├── read_yokogawa_header.m │ │ ├── read_yokogawa_header_new.m │ │ ├── refine.m │ │ ├── removefields.m │ │ ├── renamefields.m │ │ ├── sn2individual.m │ │ ├── surf_to_tetgen.m │ │ ├── tokenize.m │ │ ├── write_nifti2_hdr.m │ │ ├── write_off.m │ │ ├── write_ply.m │ │ ├── write_stl.m │ │ └── write_vtk.m ├── emptyfile.txt ├── load_fMRI.m ├── nanconv │ ├── license.txt │ └── nanconv.m ├── parcellation_template.mat ├── parcellation_template22_RightBrain_subject1-100.mat ├── parcellation_template7.mat ├── pattDetection_v4.m ├── preproc_fRMI.m ├── region_of_coordination_ROC.m ├── spaceFreq_fMRI.m ├── spiral_classifer_language_task.m ├── spiral_contrast_significance.m ├── spiral_detection_surfilt.m ├── spiral_distribution_zscore_map_speed_duration_radius_count.m ├── spiral_interaction_statistics.m ├── task_evoked_unfiltered_fMRI_signal.m └── task_specific_spiral_distribution.m └── Videos ├── Supplementary_Video_S1.avi ├── Supplementary_Video_S2.avi ├── Supplementary_Video_S3.avi ├── Supplementary_Video_S4.avi ├── Supplementary_Video_S5.avi ├── Supplementary_Video_S6.avi └── Video captions.docx /README.md: -------------------------------------------------------------------------------- 1 | # BrainVortexToolbox 2 | MATLAB toolbox to automatically detect and analyse spiral wave patterns in the fMRI data, developed by Dr. Pulin Gong's group at University of Sydney. 3 | 4 | ## Instructions for use 5 | System dependencies: N/A
6 | Software version: MATLAB 2016b and above (has been tested on MATLAB 2016b and 2020a)
7 | Hardware requirement: N/A 8 | 9 | Data format: fMRI data in standard CIFTI grayordinate space, comprising 32K cortical vertices
10 | Data tested: 100 subjects from the Human Connectomb Project (HCP)
[https://db.humanconnectome.org/data/projects/HCP_1200] 11 | 12 | ### Launch:
13 | Sample data is not avaialble in GitHub due to size limitation, please download from the HCP site link above. No subject ID is provided as all subjects should be selected randomly from a corhort of 1200 subjects. 14 | 15 | Please download all folders from this repository and allocate the raw fMRI data files (i.e., 'tfMRI_LANGUAGE_LR_Atlas.dtseries.nii') and structural data files (i.e.,'L.flat.32k_fs_LR.surf.gii') downloaded from HCP database into subfolders named by the subject ID under 'Raw Data' and 'Data Pos' folders, repectively. For task state data, please also download the task label files for each subject (witihn the 'EVs' subfolder next to the raw fMRI data file). 16 | 17 | For example, the data under subject ID 100206 recorded during a language task should be allocated in the following folders:
18 | Raw fMRI data: '/main_folder/Sample Data/Language Task Original 100 sub/Raw Data/100206/tfMRI_LANGUAGE_LR_Atlas.dtseries.nii';
19 | Structural data: '/main_folder/Sample Data/Language Task Original 100 sub/Data Pos/100206/L.flat.32k_fs_LR.surf.gii';
20 | Task label files: '/main_folder/Sample Data/Language Task Original 100 sub/Raw Data/100206/EVs/present_math.txt';
21 | 22 | Run 'Results_main.m' in matlab to generate key results and figures. 23 | 24 | 25 | 26 | ### Main function: 27 | 28 | Results_main.m (directory to all subfunctions, from preprocessing to spiral detection to sprial-based analysis) 29 | 30 | ### Subfunctions: 31 | 32 | Preprocessing_main.m (pre-preocessing of raw fMRI data with/without spatiotemporal bandpassfilters)
33 | load_fMRI.m
34 | preproc_fRMI.m
35 | spaceFreq_fMRI.m
36 | bandpa_fMRI.m
37 | ft_read_cifti.m
38 | gifti.m
39 | 40 | spiral_detection_surfilt.m (spiral detection and filtering based on the statistical test against the null model)
41 | anglesubtract.m
42 | pattDetection_v4.m
43 | 44 | spiral_distribution_zscore_map_speed_duration_radius_count.m (spiral distribution z-score map, propagation speed, duration, radius and spiral count)
45 | 46 | distance_vs_amplitude.m (relationship between fMRI amplitude and its distance to spiral centres)
47 | 48 | spiral_interaction_statistics.m (% proportion of spiral-spiral interactions among three interaction types)
49 | 50 | TaskLabel_Extract.m (extract task labels of each subject)
51 | 52 | task_specific_spiral_distribution.m (trial-averaged spiral distribution maps across all subjects under each task condition)
53 | 54 | spiral_contrast_significance.m (spiral contrast significance maps between different task conditions and their density in 7 functional networks)
55 | 56 | spiral_classifer_language_task.m (spiral centre-based linear classifier)
57 | 58 | task_evoked_unfiltered_fMRI_signal.m (spiral detection based on task-evoked trial-averaged unfiltered fMRI signals)
59 | 60 | PCA.m (principle component analysis of the regional rotational dynamics in the task-evoked trial-averaged unfiltered fMRI signals)
61 | 62 | region_of_coordination_ROC.m (identification of the ROC) 63 | 64 | PhaseVectorAngle_local_classifier.m (local phase vector field-based linear classifier) 65 | 66 | ## Expected output
67 | Key figures in the paper "Interacting spiral wave patterns underlie complex brain dynamics and are related to cognitive processing" will be generated. 68 | 69 | figure 2d. Population-combined z-score maps of brain spiral density in the flattened left cortex
70 | spiral_distribution_zscore_map_speed_duration_radius_count.m 71 | 72 | figure 2e. fMRI amplitude vs. distance from singularity.
73 | distance_vs_amplitude.m 74 | 75 | figure 3e. spiral propagation speed distribution.
76 | spiral_distribution_zscore_map_speed_duration_radius_count.m 77 | 78 | figure 4a. spiral interaction type statistics.
79 | spiral_interaction_statistics.m 80 | 81 | figure 5 1st and 2nd columns. task-specific spiral distribution maps.
82 | task_specific_spiral_distribution.m 83 | 84 | figure 5 3rd column. spiral contrast significance maps.
85 | spiral_contrast_significance.m 86 | 87 | figure 6a. spiral contrast significance density across 7 functional networks.
88 | spiral_contrast_significance.m 89 | 90 | figure 6b-c. sprial centre-based linear classifer performances.
91 | spiral_classifer_language_task.m 92 | 93 | figure7a-c. sprial detected in task-evoked (trial-averaged) unfiltered fMRI signals.
94 | task_evoked_unfiltered_fMRI_signal.m 95 | 96 | figure7d. principle component analysis of the regional rotational dynamics in the task-evoked trial-averaged unfiltered fMRI signals.
97 | PCA.m 98 | 99 | figure8b & d. identification of the region of coordination (ROC).
100 | region_of_coordination_ROC.m 101 | 102 | figure8c. local phase vector field-based linear classifier.
103 | PhaseVectorAngle_local_classifier.m 104 | 105 | 106 | 107 | ## Authors 108 | 109 | * **Yiben Xu** - yixu4976@uni.sydney.edu.au 110 | * **Xian Long** - [Xian Long](https://github.com/longxian319) 111 | * **Pulin Gong** - pulin.gong@sydney.edu.au 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /Sample Data/Language Task Additional 100 sub/Analysis/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Language Task Additional 100 sub/Analysis/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Language Task Additional 100 sub/Data Pos/300618/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Language Task Additional 100 sub/Data Pos/300618/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Language Task Additional 100 sub/Data Pos/300719/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Language Task Additional 100 sub/Data Pos/300719/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Language Task Additional 100 sub/Preprocessed Data/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Language Task Additional 100 sub/Preprocessed Data/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Language Task Additional 100 sub/Raw Data/300618/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Language Task Additional 100 sub/Raw Data/300618/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Language Task Additional 100 sub/Raw Data/300719/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Language Task Additional 100 sub/Raw Data/300719/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Language Task Additional 100 sub/Spiral Detected/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Language Task Additional 100 sub/Spiral Detected/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Language Task Additional 100 sub/TaskLabel/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Language Task Additional 100 sub/TaskLabel/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Language Task Original 100 sub/Analysis/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Language Task Original 100 sub/Analysis/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Language Task Original 100 sub/Preprocessed Data/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Language Task Original 100 sub/Preprocessed Data/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Language Task Original 100 sub/Raw Data/300618/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Language Task Original 100 sub/Raw Data/300618/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Language Task Original 100 sub/Raw Data/300719/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Language Task Original 100 sub/Raw Data/300719/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Language Task Original 100 sub/Spiral Detected/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Language Task Original 100 sub/Spiral Detected/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Language Task Original 100 sub/TaskLabel/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Language Task Original 100 sub/TaskLabel/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Resting/Analysis/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Resting/Analysis/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Resting/Preprocessed Data/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Resting/Preprocessed Data/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Resting/Raw Data/100206/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Resting/Raw Data/100206/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Resting/Raw Data/100610/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Resting/Raw Data/100610/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/Resting/Spiral Detected/EmptyFile.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/Resting/Spiral Detected/EmptyFile.txt -------------------------------------------------------------------------------- /Sample Data/parcellation_template.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/parcellation_template.mat -------------------------------------------------------------------------------- /Sample Data/parcellation_template7.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sample Data/parcellation_template7.mat -------------------------------------------------------------------------------- /Sub-function/PCA.m: -------------------------------------------------------------------------------- 1 | function [score,latent] = PCA(flagSur,hemisphere,main_folder,No_of_Subject,flagTask,listen_or_answer,motor_or_PCC); 2 | 3 | %% PCA analysis of raw amplitude map, mathlisten 1-20 4 | 5 | % load task-evoked unfiltered trial averaged fMRI signal file 6 | foldername = [main_folder,'/Sample Data/Language Task Original 100 sub/Analysis']; 7 | cd(foldername) 8 | filename = ['task_evoked_unfiltered_fMRI_signal.mat']; 9 | load(filename) 10 | 11 | % min-max normalization 12 | 13 | data_math_listen_avg_max = nanmax(data_math_listen_avg,[],3); 14 | data_math_listen_avg_min = nanmin(data_math_listen_avg,[],3); 15 | data_math_listen_avg_minmaxnorm = (data_math_listen_avg-data_math_listen_avg_min)./(data_math_listen_avg_max-data_math_listen_avg_min); 16 | 17 | data_math_answer_avg_max = nanmax(data_math_answer_avg,[],3); 18 | data_math_answer_avg_min = nanmin(data_math_answer_avg,[],3); 19 | data_math_answer_avg_minmaxnorm = (data_math_answer_avg-data_math_answer_avg_min)./(data_math_answer_avg_max-data_math_answer_avg_min); 20 | 21 | 22 | %% 23 | if hemisphere == 1 24 | if listen_or_answer == 1 25 | if motor_or_PCC == 1 26 | temp1 = permute(data_math_listen_avg_minmaxnorm(90:120,110:140,:),[3,1,2]); % left-motor/premotor 27 | elseif motor_or_PCC == 2 28 | temp1 = permute(data_math_listen_avg_minmaxnorm(128:158,175:205,:),[3,1,2]); % left-PCC-listen 29 | end 30 | elseif listen_or_answer == 2 31 | temp1 = permute(data_math_answer_avg_minmaxnorm(90:120,110:140,:),[3,1,2]); % left-motor/premotor 32 | end 33 | elseif hemisphere == 2 34 | if listen_or_answer == 1 35 | if motor_or_PCC == 1 36 | temp1 = permute(data_math_listen_avg_minmaxnorm(105:135,120:150,:),[3,1,2]); % right-listen Mor 37 | elseif motor_or_PCC == 2 38 | temp1 = permute(data_math_listen_avg_minmaxnorm(128:158,65:95,:),[3,1,2]); % right-listen_PCC 39 | end 40 | elseif listen_or_answer == 2 41 | temp1 = permute(data_math_answer_avg_minmaxnorm(95:125,120:150,:),[3,1,2]); % right-listen PCC 42 | end 43 | end 44 | temp2 = reshape(temp1,20,[]); 45 | 46 | [coeff,score,latent,tsquared,explained,mu] = pca(temp2); 47 | 48 | figure(); 49 | hold on 50 | for iTime = 1:1 %size(score,1) 51 | if hemisphere == 1 52 | if listen_or_answer == 1 53 | p = plot3(score(iTime:iTime+19,2),score(iTime:iTime+19,1),score(iTime:iTime+19,3),'b') 54 | p.LineWidth = 2; 55 | scatter3(score(1,2),score(1,1),score(1,3),35,'b','filled') 56 | elseif listen_or_answer == 2 57 | p = plot3(score(iTime:iTime+19,2),score(iTime:iTime+19,1),score(iTime:iTime+19,3),'b-') 58 | p.LineWidth = 2; 59 | scatter3(score(1,2),score(1,1),score(1,3),35,'b','filled') 60 | end 61 | elseif hemisphere == 2 62 | if listen_or_answer == 1 63 | p = plot3(score(iTime:iTime+19,2),score(iTime:iTime+19,1),score(iTime:iTime+19,3),'r') 64 | scatter3(score(1,2),score(1,1),score(1,3),35,'r','filled') 65 | p.LineWidth = 2; 66 | elseif listen_or_answer == 2 67 | p = plot3(score(iTime:iTime+19,2),score(iTime:iTime+19,1),score(iTime:iTime+19,3),'r-') 68 | p.LineWidth = 2; 69 | scatter3(score(1,2),score(1,1),score(1,3),35,'r','filled') 70 | end 71 | end 72 | xlim([-15,15]) 73 | ylim([-15,15]) 74 | % title(['task-evoked raw amplitude, listen 1-20, RIGHT PCC, PCA, PC1=',num2str(latent(1)),'% variance, PC2=',num2str(latent(2)),'%']) 75 | title(['task-evoked raw amplitude, math listen 1-20, LEFT M1-PMd, PCA, PC1=',num2str(latent(1)),'% variance, PC2=',num2str(latent(2)),'%']) 76 | end 77 | 78 | 79 | end -------------------------------------------------------------------------------- /Sub-function/anglesubtract.m: -------------------------------------------------------------------------------- 1 | function xydiff = anglesubtract(x, y, angleFlag) 2 | % ANGLESUBTRACT Subtracts the matrix y from the equally sized matrix x and 3 | % returns a value between -pi and +pi. This is valid if x and y both 4 | % contain angular data in radians. If angleFlag is false, returns a 5 | % non-angular subtraction. 6 | % 7 | % Rory Townsend, Oct 2017 8 | % rory.townsend@sydney.edu.au 9 | 10 | % Assume input is angular if unspecified 11 | if nargin < 3 12 | angleFlag = 1; 13 | end 14 | 15 | if angleFlag == 1 16 | % METHOD 1: Modulo method 17 | xydiff = mod(x - y + pi, 2*pi) - pi; 18 | 19 | % METHOD 2: Trig method, works but is slower 20 | % xydiff2 = atan2(sin(x-y), cos(x-y)); 21 | 22 | else 23 | xydiff = x - y; 24 | end 25 | 26 | end -------------------------------------------------------------------------------- /Sub-function/bandpa_fMRI.m: -------------------------------------------------------------------------------- 1 | function [bandpasSig, hilbertSig, ampSig, phaseSig] = bandpa_fMRI(sigValid,fs,fLow,fHigh) ; 2 | % bandpass the fMRI data 3 | % output: bandpassSig, hilbertSig, ampSig, phaseSig 4 | 5 | % % Design Butterworth band-pass filter 6 | % h = fdesign.bandpass('N,F3dB1,F3dB2',6,fLow,fHigh,fs); 7 | % Hd = design(h, 'butter'); 8 | % set(Hd, 'Arithmetic', 'double'); 9 | % 10 | % SOS = Hd.sosMatrix; 11 | % G = Hd.ScaleValues; 12 | 13 | [z,p,k]=butter(4,[fLow fHigh]/(fs/2),'bandpass'); 14 | % [z,p,k]=butter(4,[fLow]/(fs/2),'low'); 15 | [sos,g]=zp2sos(z,p,k); 16 | [b, a]=butter(4,[fLow fHigh]/(fs/2),'bandpass'); 17 | % [b, a]=butter(4,[fLow]/(fs/2),'low'); 18 | 19 | badChannels = find(isnan(sigValid(:,1))==1) ; 20 | bandpasSig = nan(size(sigValid)) ; 21 | hilbertSig = nan(size(sigValid)) ; 22 | phaseSig = nan(size(sigValid)) ; 23 | ampSig = nan(size(sigValid)) ; 24 | 25 | % which filtfilt 26 | disp('start fitlering...'); 27 | tic 28 | for iNode = setdiff(1:size(sigValid,1),badChannels) 29 | sigOriDemean = (sigValid(iNode,:)-mean(sigValid(iNode,:))) ; 30 | % bandpasSig(iNode,:) = filter(b,a,sigValid(iNode,:)); 31 | bandpasSig(iNode,:) = filtfilt(sos,g,sigOriDemean); % may be corrupted by 32 | % fieldtrip toolbox 33 | hilbertSig(iNode,:) = hilbert(bandpasSig(iNode,:)) ; 34 | phaseSig(iNode,:) = angle(hilbertSig(iNode,:)) ; 35 | ampSig(iNode,:) = abs(hilbertSig(iNode,:)) ; 36 | end 37 | toc -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/Contents.m: -------------------------------------------------------------------------------- 1 | % GIfTI Class for MATLAB 2 | % 3 | % Geometry format under the Neuroimaging Informatics Technology Initiative 4 | % (NIfTI): 5 | % http://www.nitrc.org/projects/gifti/ 6 | % http://nifti.nimh.nih.gov/ 7 | % 8 | % This MATLAB class is part of SPM: 9 | % http://www.fil.ion.ucl.ac.uk/spm/ 10 | % 11 | % It relies on external libraries: 12 | % Base64, by Peter J. Acklam: 13 | % http://home.online.no/~pjacklam/ 14 | % miniz, by Rich Geldreich: 15 | % http://code.google.com/p/miniz/ 16 | % XMLTree, by Guillaume Flandin: 17 | % http://www.artefact.tk/software/matlab/xml/ 18 | %__________________________________________________________________________ 19 | % Copyright (C) 2008-2015 Wellcome Trust Centre for Neuroimaging 20 | 21 | % Guillaume Flandin 22 | % $Id: Contents.m 6404 2015-04-13 14:29:53Z guillaume $ 23 | 24 | % GIfTI file format for MATLAB (The Mathworks, Inc.). 25 | % Copyright (C) 2008-2015 Wellcome Trust Centre for Neuroimaging 26 | % 27 | % This program is free software; you can redistribute it and/or 28 | % modify it under the terms of the GNU General Public License 29 | % as published by the Free Software Foundation; either version 2 30 | % of the License, or any later version. 31 | % 32 | % This program is distributed in the hope that it will be useful, 33 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 34 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 35 | % GNU General Public License for more details. 36 | % 37 | % You should have received a copy of the GNU General Public License 38 | % along with this program; if not, write to the Free Software 39 | % Foundation Inc, 59 Temple Pl. - Suite 330, Boston, MA 02111-1307, USA. -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/display.m: -------------------------------------------------------------------------------- 1 | function display(this) 2 | % Display method for GIfTI objects 3 | % FORMAT display(this) 4 | % this - GIfTI object 5 | %__________________________________________________________________________ 6 | % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging 7 | 8 | % Guillaume Flandin 9 | % $Id: display.m 4182 2011-02-01 12:29:09Z guillaume $ 10 | 11 | display_name = inputname(1); 12 | if isempty(display_name) 13 | display_name = 'ans'; 14 | end 15 | 16 | if length(this) == 1 && ~isempty(this.data) 17 | eval([display_name ' = struct(this);']); 18 | eval(['display(' display_name ');']); 19 | else 20 | disp(' ') 21 | disp([display_name ' =']); 22 | disp(' '); 23 | eval([display_name ' = this;']); 24 | eval(['disp(' display_name ');']); 25 | end -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/export.m: -------------------------------------------------------------------------------- 1 | function s = export(this,target) 2 | % Export a GIfTI object into specific MATLAB struct 3 | % FORMAT s = export(this,target) 4 | % this - GIfTI object 5 | % target - string describing target output [default: MATLAB] 6 | % s - a structure containing public fields of the object 7 | %__________________________________________________________________________ 8 | % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging 9 | 10 | % Guillaume Flandin 11 | % $Id: export.m 6401 2015-04-09 17:21:33Z guillaume $ 12 | 13 | if numel(this) > 1, warning('Only handle scalar objects yet.'); end 14 | 15 | if nargin <= 1, target = 'MATLAB'; end 16 | 17 | switch lower(target) 18 | case 'matlab' 19 | s = struct(this); 20 | 21 | case 'patch' 22 | if isfield(this,'vertices') 23 | s.vertices = double(subsref(this, substruct('.', 'vertices'))); 24 | end 25 | if isfield(this,'faces') 26 | s.faces = subsref(this, substruct('.', 'faces')); 27 | end 28 | if isfield(this,'cdata') 29 | s.facevertexcdata = double(subsref(this, substruct('.', 'cdata'))); 30 | end 31 | try, s; catch, s = struct([]); end 32 | 33 | case {'fieldtrip', 'ft'} 34 | s = struct('tri',[], 'pnt',[]); 35 | if isfield(this,'vertices') 36 | s.pnt = double(subsref(this, substruct('.', 'vertices'))); 37 | end 38 | if isfield(this,'faces') 39 | s.tri = double(subsref(this, substruct('.', 'faces'))); 40 | end 41 | 42 | case {'spm'} 43 | s = struct('face',[], 'vert',[]); 44 | if isfield(this,'vertices') 45 | s.vert = double(subsref(this, substruct('.', 'vertices'))); 46 | end 47 | if isfield(this,'faces') 48 | s.face = uint32(subsref(this, substruct('.', 'faces'))); 49 | end 50 | 51 | otherwise 52 | error('Unknown target ''%s''.', target); 53 | end 54 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/fieldnames.m: -------------------------------------------------------------------------------- 1 | function names = fieldnames(this) 2 | % Fieldnames method for GIfTI objects 3 | % FORMAT names = fieldnames(this) 4 | % this - GIfTI object 5 | % names - field names 6 | %__________________________________________________________________________ 7 | % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging 8 | 9 | % Guillaume Flandin 10 | % $Id: fieldnames.m 6507 2015-07-24 16:48:02Z guillaume $ 11 | 12 | if numel(this) > 1, warning('Only handle scalar objects yet.'); end 13 | 14 | pfn = {'vertices','faces','normals','cdata','mat','labels','indices'}; 15 | 16 | names = unique(pfn(isintent(this,pfn))); 17 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/gifti.m: -------------------------------------------------------------------------------- 1 | function this = gifti(varargin) 2 | % GIfTI Geometry file format class 3 | % Geometry format under the Neuroimaging Informatics Technology Initiative 4 | % (NIfTI): 5 | % http://www.nitrc.org/projects/gifti/ 6 | % http://nifti.nimh.nih.gov/ 7 | %__________________________________________________________________________ 8 | % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging 9 | 10 | % Guillaume Flandin 11 | % $Id: gifti.m 6347 2015-02-24 17:59:16Z guillaume $ 12 | 13 | switch nargin 14 | 15 | case 0 16 | this = giftistruct; 17 | this = class(this,'gifti'); 18 | 19 | case 1 20 | if isa(varargin{1},'gifti') 21 | this = varargin{1}; 22 | 23 | elseif isstruct(varargin{1}) 24 | f = {'faces', 'face', 'tri' 'vertices', 'vert', 'pnt', 'cdata', 'indices'}; 25 | ff = {'faces', 'faces', 'faces', 'vertices', 'vertices', 'vertices', 'cdata', 'indices'}; 26 | [c, ia] = intersect(f,fieldnames(varargin{1})); 27 | if ~isempty(c) 28 | this = gifti; 29 | for i=1:length(c) 30 | this = subsasgn(this,... 31 | struct('type','.','subs',ff{ia(i)}),... 32 | varargin{1}.(c{i})); 33 | end 34 | elseif isempty(setxor(fieldnames(varargin{1}),... 35 | {'metadata','label','data'})) 36 | this = class(varargin{1},'gifti'); 37 | else 38 | error('[GIFTI] Invalid structure.'); 39 | end 40 | 41 | elseif ishandle(varargin{1}) 42 | this = struct('vertices',get(varargin{1},'Vertices'), ... 43 | 'faces', get(varargin{1},'Faces')); 44 | if ~isempty(get(varargin{1},'FaceVertexCData')); 45 | this.cdata = get(varargin{1},'FaceVertexCData'); 46 | end 47 | this = gifti(this); 48 | 49 | elseif isnumeric(varargin{1}) 50 | this = gifti; 51 | this = subsasgn(this,... 52 | struct('type','.','subs','cdata'),... 53 | varargin{1}); 54 | 55 | elseif ischar(varargin{1}) 56 | if size(varargin{1},1)>1 57 | this = gifti(cellstr(varargin{1})); 58 | return; 59 | end 60 | [p,n,e] = fileparts(varargin{1}); 61 | if strcmpi(e,'.mat') 62 | try 63 | this = gifti(load(varargin{1})); 64 | catch 65 | error('[GIFTI] Loading of file %s failed.', varargin{1}); 66 | end 67 | elseif strcmpi(e,'.asc') || strcmpi(e,'.srf') 68 | this = read_freesurfer_file(varargin{1}); 69 | this = gifti(this); 70 | else 71 | this = read_gifti_file_standalone(varargin{1},giftistruct); 72 | this = class(this,'gifti'); 73 | end 74 | 75 | elseif iscellstr(varargin{1}) 76 | fnames = varargin{1}; 77 | this(numel(fnames)) = giftistruct; 78 | this = class(this,'gifti'); 79 | for i=1:numel(fnames) 80 | this(i) = gifti(fnames{i}); 81 | end 82 | 83 | else 84 | error('[GIFTI] Invalid object construction.'); 85 | end 86 | 87 | otherwise 88 | error('[GIFTI] Invalid object construction.'); 89 | end 90 | 91 | %========================================================================== 92 | function s = giftistruct 93 | s = struct(... 94 | 'metadata', ... 95 | struct(... 96 | 'name', {}, ... 97 | 'value', {} ... 98 | ), ... 99 | 'label', ... 100 | struct(... 101 | 'name', {}, ... 102 | 'index', {} ... 103 | ), ... 104 | 'data', ... 105 | struct(... 106 | 'attributes', {}, ... 107 | 'metadata', struct('name',{}, 'value',{}), ... 108 | 'space', {}, ... 109 | 'data', {} ... 110 | ) ... 111 | ); 112 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/isfield.m: -------------------------------------------------------------------------------- 1 | function tf = isfield(this,field) 2 | % Isfield method for GIfTI objects 3 | % FORMAT tf = isfield(this,field) 4 | % this - GIfTI object 5 | % field - string of cell array 6 | % tf - logical array 7 | %__________________________________________________________________________ 8 | % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging 9 | 10 | % Guillaume Flandin 11 | % $Id: isfield.m 6507 2015-07-24 16:48:02Z guillaume $ 12 | 13 | tf = ismember(field, fieldnames(this)); 14 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/plot.m: -------------------------------------------------------------------------------- 1 | function varargout = plot(varargin) 2 | % plot method for GIfTI objects 3 | %__________________________________________________________________________ 4 | % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging 5 | 6 | % Guillaume Flandin 7 | % $Id: plot.m 5888 2014-02-19 19:54:12Z guillaume $ 8 | 9 | % if ishandle(varargin{1}) 10 | % h = figure(varargin{1}); 11 | % else 12 | % h = figure; 13 | % %axis equal; 14 | % %axis off; 15 | % %camlight; 16 | % %camlight(-80,-10); 17 | % %lighting phong; 18 | % end 19 | % cameramenu; 20 | 21 | 22 | cdata = []; 23 | ax = []; 24 | if nargin == 1 25 | this = varargin{1}; 26 | h = gcf; 27 | else 28 | if ishandle(varargin{1}) 29 | ax = varargin{1}; 30 | h = figure(get(ax,'parent')); 31 | this = varargin{2}; 32 | else 33 | this = varargin{1}; 34 | h = gcf; 35 | cdata = subsref(varargin{2},struct('type','.','subs','cdata')); 36 | end 37 | if nargin > 2 38 | indc = varargin{3}; 39 | else 40 | indc = 1; 41 | end 42 | end 43 | 44 | if isempty(ax), ax = axes('Parent',h); end 45 | axis(ax,'equal'); 46 | axis(ax,'off'); 47 | hp = patch(struct(... 48 | 'vertices', subsref(this,struct('type','.','subs','vertices')),... 49 | 'faces', subsref(this,struct('type','.','subs','faces'))),... 50 | 'FaceColor', 'b',... 51 | 'EdgeColor', 'none',... 52 | 'Parent',ax); 53 | 54 | if ~isempty(cdata) 55 | set(hp,'FaceVertexCData',cdata(:,indc), 'FaceColor','interp') 56 | end 57 | 58 | axes(ax); 59 | camlight; 60 | camlight(-80,-10); 61 | lighting phong; 62 | axes(ax); 63 | cameramenu; 64 | 65 | if nargout 66 | varargout{1} = hp; 67 | end 68 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/private/Makefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env make -f 2 | # GIfTI Makefile 3 | # 4 | # Copyright (C) 2015 Wellcome Trust Centre for Neuroimaging 5 | # 6 | # $Id: Makefile 6402 2015-04-09 18:11:06Z guillaume $ 7 | 8 | include Makefile.var 9 | 10 | SPMMEX = zstream.$(SUF) 11 | 12 | ifeq (mex,$(SUF)) 13 | export CFLAGS = $(shell $(MEX) -p CFLAGS) -std=c99 14 | else 15 | MEXOPTS += CFLAGS='$$CFLAGS -std=c99' 16 | endif 17 | 18 | all: $(SPMMEX) 19 | @: 20 | 21 | clean: 22 | @: 23 | 24 | distclean: clean 25 | $(DEL) $(SPMMEX) 26 | 27 | install: 28 | @: 29 | 30 | tarball: all 31 | $(TAR) cf spm_mex.tar $(SPMMEX) 32 | 33 | %.$(SUF) : %.c 34 | $(MEX) $< $(MEXEND) 35 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/private/Makefile.var: -------------------------------------------------------------------------------- 1 | # Makefile default variables 2 | # 3 | # Copyright (C) 1991-2014 Wellcome Trust Centre for Neuroimaging 4 | # 5 | # $Id: Makefile.var 6099 2014-07-11 12:21:35Z guillaume $ 6 | # 7 | ############################################################################### 8 | # 9 | # This file defines variables used in Makefile and has been tested under 10 | # Linux, Windows and MacOS. 11 | # 12 | # If you have to tweak this file to compile the SPM MEX-files for your 13 | # platform, please send the details to so they can be 14 | # included here. 15 | # 16 | # You can find some more help online on the SPM wikibook: 17 | # * Linux: 18 | # http://en.wikibooks.org/wiki/SPM/Installation_on_Linux 19 | # http://en.wikibooks.org/wiki/SPM/Installation_on_64bit_Linux 20 | # * Windows: 21 | # http://en.wikibooks.org/wiki/SPM/Installation_on_Windows 22 | # http://en.wikibooks.org/wiki/SPM/Installation_on_64bit_Windows 23 | # MinGW: http://www.mingw.org/ 24 | # * MacOS: 25 | # http://en.wikibooks.org/wiki/SPM/Installation_on_Mac_OS_(Intel) 26 | # http://en.wikibooks.org/wiki/SPM/Installation_on_64bit_Mac_OS_(Intel) 27 | # 28 | ############################################################################### 29 | 30 | SHELL = /bin/sh 31 | MAKE = make 32 | MEXBIN = mex 33 | MEXOPTS = -O -largeArrayDims 34 | MEXEND = 35 | MOSUF = o # mex output object suffix 36 | UNAME = uname 37 | AR = ar rcs 38 | COPY = cp -f 39 | DEL = rm -f 40 | MOVE = mv -f 41 | TAR = tar 42 | ZIP = gzip -f 43 | 44 | ifndef SUF 45 | ifndef PLATFORM 46 | PLATFORM = $(shell $(UNAME)) 47 | endif 48 | ##### Linux ##### 49 | ifeq (Linux,$(PLATFORM)) 50 | HARDWARE = $(shell $(UNAME) -m) 51 | ifeq (i386,$(HARDWARE)) 52 | SUF = mexglx 53 | endif 54 | ifeq (i686,$(HARDWARE)) 55 | SUF = mexglx 56 | endif 57 | ifeq (x86_64,$(HARDWARE)) 58 | SUF = mexa64 59 | endif 60 | ifndef SUF 61 | $(error Unknowm platform $(PLATFORM)-$(HARDWARE)) 62 | endif 63 | endif 64 | ##### MacOS ##### 65 | ifeq (Darwin,$(PLATFORM)) 66 | HARDWARE = $(shell $(UNAME) -p) 67 | ifeq (i386,$(HARDWARE)) 68 | SUF = mexmaci64 69 | endif 70 | ifndef SUF 71 | $(error Unknowm platform $(PLATFORM)-$(HARDWARE)) 72 | endif 73 | endif 74 | ##### Windows ##### 75 | ifeq (MINGW32,$(word 1,$(subst _, ,$(PLATFORM)))) 76 | override PLATFORM = windows 77 | endif 78 | ifeq (windows,$(PLATFORM)) 79 | ifeq (x86,$(PROCESSOR_ARCHITECTURE)) 80 | SUF = mexw32 81 | else 82 | SUF = mexw64 83 | endif 84 | MEXBIN = cmd /c "mex.bat 85 | MEXOPTS += -DSPM_WIN32 86 | MEXEND = " 87 | MOSUF = obj 88 | AR = lib.exe /out: 89 | endif 90 | #### Octave #### 91 | ifeq (octave,$(PLATFORM)) 92 | MEXBIN = mkoctfile 93 | MEXOPTS = --mex 94 | SUF = mex 95 | override PLATFORM = $(shell $(UNAME)) 96 | endif 97 | ifndef SUF 98 | $(error Unknowm platform $(PLATFORM)) 99 | endif 100 | endif 101 | 102 | MEX = $(MEXBIN) $(MEXOPTS) 103 | 104 | MATLABROOT = $(realpath $(shell which $(firstword $(MEXBIN)))) 105 | 106 | define verb 107 | @ echo "_____________________________________________________________" 108 | @ echo "" 109 | @ echo " " $(1) 110 | @ echo "_____________________________________________________________" 111 | @ echo "" 112 | endef 113 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/private/base64decode.m: -------------------------------------------------------------------------------- 1 | function y = base64decode(x) 2 | %BASE64DECODE Perform base64 decoding on a string. 3 | % 4 | % BASE64DECODE(STR) decodes the given base64 string STR. 5 | % 6 | % Any character not part of the 65-character base64 subset set is silently 7 | % ignored. 8 | % 9 | % This function is used to decode strings from the Base64 encoding specified 10 | % in RFC 2045 - MIME (Multipurpose Internet Mail Extensions). The Base64 11 | % encoding is designed to represent arbitrary sequences of octets in a form 12 | % that need not be humanly readable. A 65-character subset ([A-Za-z0-9+/=]) 13 | % of US-ASCII is used, enabling 6 bits to be represented per printable 14 | % character. 15 | % 16 | % See also BASE64ENCODE. 17 | 18 | % Author: Peter J. Acklam 19 | % Time-stamp: 2004-09-20 08:20:50 +0200 20 | % E-mail: pjacklam@online.no 21 | % URL: http://home.online.no/~pjacklam 22 | 23 | % Modified by Guillaume Flandin, May 2008 24 | 25 | 26 | % Perform the following mapping 27 | %-------------------------------------------------------------------------- 28 | % A-Z -> 0 - 25 a-z -> 26 - 51 0-9 -> 52 - 61 29 | % + -> 62 / -> 63 = -> 64 30 | % anything else -> NaN 31 | 32 | base64chars = NaN(1,256); 33 | base64chars('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=') = 0:64; 34 | x = base64chars(x); 35 | 36 | % Remove/ignore any characters not in the base64 characters list or '=' 37 | %-------------------------------------------------------------------------- 38 | 39 | x = x(~isnan(x)); 40 | 41 | % Replace any incoming padding ('=' -> 64) with a zero pad 42 | %-------------------------------------------------------------------------- 43 | 44 | if x(end-1) == 64, p = 2; x(end-1:end) = 0; 45 | elseif x(end) == 64, p = 1; x(end) = 0; 46 | else p = 0; 47 | end 48 | 49 | % Allocate decoded data array 50 | %-------------------------------------------------------------------------- 51 | 52 | n = length(x) / 4; % number of groups 53 | x = reshape(uint8(x), 4, n); % input data 54 | y = zeros(3, n, 'uint8'); % decoded data 55 | 56 | % Rearrange every 4 bytes into 3 bytes 57 | %-------------------------------------------------------------------------- 58 | % 00aaaaaa 00bbbbbb 00cccccc 00dddddd 59 | % 60 | % to form 61 | % 62 | % aaaaaabb bbbbcccc ccdddddd 63 | 64 | y(1,:) = bitshift(x(1,:), 2); % 6 highest bits of y(1,:) 65 | y(1,:) = bitor(y(1,:), bitshift(x(2,:), -4)); % 2 lowest bits of y(1,:) 66 | 67 | y(2,:) = bitshift(x(2,:), 4); % 4 highest bits of y(2,:) 68 | y(2,:) = bitor(y(2,:), bitshift(x(3,:), -2)); % 4 lowest bits of y(2,:) 69 | 70 | y(3,:) = bitshift(x(3,:), 6); % 2 highest bits of y(3,:) 71 | y(3,:) = bitor(y(3,:), x(4,:)); % 6 lowest bits of y(3,:) 72 | 73 | % Remove any zero pad that was added to make this a multiple of 24 bits 74 | %-------------------------------------------------------------------------- 75 | 76 | if p, y(end-p+1:end) = []; end 77 | 78 | % Reshape to a row vector 79 | %-------------------------------------------------------------------------- 80 | 81 | y = reshape(y, 1, []); 82 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/private/getdict.m: -------------------------------------------------------------------------------- 1 | function d = getdict 2 | % Dictionary of GIfTI/NIfTI stuff 3 | %__________________________________________________________________________ 4 | % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging 5 | 6 | % Guillaume Flandin 7 | % $Id: getdict.m 4505 2011-09-30 11:45:58Z guillaume $ 8 | 9 | persistent dict; 10 | if ~isempty(dict) 11 | d = dict; 12 | return; 13 | end 14 | 15 | table = {... 16 | 'NIFTI_TYPE_UINT8', 'uint8', '%d', @uint8, 'uint8' 17 | 'NIFTI_TYPE_INT32', 'int32', '%d', @int32, 'int32' 18 | 'NIFTI_TYPE_FLOAT32', 'float32', '%f', @single, 'single' 19 | 'NIFTI_TYPE_FLOAT64', 'float64', '%f', @double, 'double'}; 20 | 21 | for i=1:size(table,1) 22 | dict.(table{i,1}) = cell2struct({table{i,2:end}},... 23 | {'class', 'format', 'conv', 'cast'}, 2); 24 | end 25 | 26 | d = dict; -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/private/isintent.m: -------------------------------------------------------------------------------- 1 | function [a, b] = isintent(this,intent) 2 | % Correspondance between fieldnames and NIfTI intent codes 3 | % FORMAT ind = isintent(this,intent) 4 | % this - GIfTI object 5 | % intent - fieldnames 6 | % a - indices of found intent(s) 7 | % b - indices of dataarrays of found intent(s) 8 | %__________________________________________________________________________ 9 | % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging 10 | 11 | % Guillaume Flandin 12 | % $Id: isintent.m 6345 2015-02-20 12:25:50Z guillaume $ 13 | 14 | a = []; 15 | b = []; 16 | if ischar(intent), intent = cellstr(intent); end 17 | for i=1:length(this(1).data) 18 | switch this(1).data{i}.attributes.Intent(14:end) 19 | case 'POINTSET' 20 | [tf, loc] = ismember('vertices',intent); 21 | if tf 22 | a(end+1) = loc; 23 | b(end+1) = i; 24 | end 25 | [tf, loc] = ismember('mat',intent); 26 | if tf 27 | a(end+1) = loc; 28 | b(end+1) = i; 29 | end 30 | case 'TRIANGLE' 31 | [tf, loc] = ismember('faces',intent); 32 | if tf 33 | a(end+1) = loc; 34 | b(end+1) = i; 35 | end 36 | case 'VECTOR' 37 | [tf, loc] = ismember('normals',intent); 38 | if tf 39 | a(end+1) = loc; 40 | b(end+1) = i; 41 | end 42 | case 'NODE_INDEX' 43 | [tf, loc] = ismember('indices',intent); 44 | if tf 45 | a(end+1) = loc; 46 | b(end+1) = i; 47 | end 48 | case cdata 49 | [tf, loc] = ismember('cdata',intent); 50 | if tf 51 | a(end+1) = loc; 52 | b(end+1) = i; 53 | end 54 | if strcmp(this(1).data{i}.attributes.Intent(14:end),'LABEL') 55 | [tf, loc] = ismember('labels',intent); 56 | if tf 57 | a(end+1) = loc; 58 | b(end+1) = i; 59 | end 60 | end 61 | otherwise 62 | fprintf('Intent %s is ignored.\n',this.data{i}.attributes.Intent); 63 | end 64 | end 65 | %[d,i] = unique(a); 66 | %if length(d) < length(a) 67 | % warning('Several fields match intent type. Using first.'); 68 | % a = a(i); 69 | % b = b(i); 70 | %end 71 | 72 | function c = cdata 73 | 74 | c = { 75 | 'NONE' 76 | 'CORREL' 77 | 'TTEST' 78 | 'FTEST' 79 | 'ZSCORE' 80 | 'CHISQ' 81 | 'BETA' 82 | 'BINOM' 83 | 'GAMMA' 84 | 'POISSON' 85 | 'NORMAL' 86 | 'FTEST_NONC' 87 | 'CHISQ_NONC' 88 | 'LOGISTIC' 89 | 'LAPLACE' 90 | 'UNIFORM' 91 | 'TTEST_NONC' 92 | 'WEIBULL' 93 | 'CHI' 94 | 'INVGAUSS' 95 | 'EXTVAL' 96 | 'PVAL' 97 | 'LOGPVAL' 98 | 'LOG10PVAL' 99 | 'ESTIMATE' 100 | 'LABEL' 101 | 'NEURONAMES' 102 | 'GENMATRIX' 103 | 'SYMMATRIX' 104 | 'DISPVECT' 105 | 'QUATERNION' 106 | 'DIMLESS' 107 | 'TIME_SERIES' 108 | 'RGB_VECTOR' 109 | 'RGBA_VECTOR' 110 | 'SHAPE' 111 | 'CONNECTIVITY_DENSE' 112 | 'CONNECTIVITY_DENSE_TIME' 113 | 'CONNECTIVITY_PARCELLATED' 114 | 'CONNECTIVITY_PARCELLATED_TIME' 115 | 'CONNECTIVITY_CONNECTIVITY_TRAJECTORY' 116 | }; 117 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/private/read_freesurfer_file.m: -------------------------------------------------------------------------------- 1 | function this = read_freesurfer_file(filename) 2 | % Low level reader of FreeSurfer files (ASCII triangle surface file) 3 | % FORMAT this = read_freesurfer_file(filename) 4 | % filename - FreeSurfer file 5 | % 6 | % See http://wideman-one.com/gw/brain/fs/surfacefileformats.htm 7 | %__________________________________________________________________________ 8 | % Copyright (C) 2013 Wellcome Trust Centre for Neuroimaging 9 | 10 | % Guillaume Flandin 11 | % $Id: read_freesurfer_file.m 5322 2013-03-13 15:04:14Z guillaume $ 12 | 13 | 14 | fid = fopen(filename,'rt'); 15 | if fid == -1, error('Cannot open "%s".',filename); end 16 | 17 | fgetl(fid); % #!ascii 18 | N = fscanf(fid,'%d',2); 19 | this.vertices = fscanf(fid,'%f %f %f %d',[4 N(1)])'; 20 | this.faces = fscanf(fid,'%d %d %d %d',[4 N(2)])'; 21 | 22 | fclose(fid); 23 | 24 | this.vertices = this.vertices(:,1:3); 25 | this.faces = this.faces(:,1:3) + 1; 26 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/private/zstream.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: zstream.c 6417 2015-04-21 16:03:44Z guillaume $ 3 | * Guillaume Flandin 4 | */ 5 | 6 | /* mex -O CFLAGS='$CFLAGS -std=c99' -largeArrayDims zstream.c */ 7 | 8 | /* setenv CFLAGS "`mkoctfile -p CFLAGS` -std=c99" */ 9 | /* mkoctfile --mex zstream.c */ 10 | 11 | /* miniz: http://code.google.com/p/miniz/ */ 12 | #define MINIZ_NO_STDIO 13 | #define MINIZ_NO_ARCHIVE_APIS 14 | #define MINIZ_NO_TIME 15 | #define MINIZ_NO_ZLIB_APIS 16 | #include "miniz.c" 17 | 18 | #include "mex.h" 19 | 20 | /* --- GATEWAY FUNCTION --- */ 21 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 22 | { 23 | 24 | char *action; 25 | unsigned char *IN = NULL, *OUT = NULL; 26 | size_t INlen, OUTlen; 27 | 28 | /* Check for proper number of arguments */ 29 | if (nrhs < 2) 30 | mexErrMsgTxt("Not enough input arguments."); 31 | else if (nrhs > 2) 32 | mexErrMsgTxt("Too many input arguments."); 33 | else if (nlhs > 1) 34 | mexErrMsgTxt("Too many output arguments."); 35 | 36 | /* The input ACTION must be a string */ 37 | if (!mxIsChar(prhs[0])) 38 | mexErrMsgTxt("Input ACTION must be a string."); 39 | action = mxArrayToString(prhs[0]); 40 | 41 | /* The input IN must be a real uint8 array */ 42 | if (!mxIsUint8(prhs[1]) || mxIsComplex(prhs[1])) 43 | mexErrMsgTxt("Input IN must be a real uint8 array."); 44 | 45 | INlen = mxGetNumberOfElements(prhs[1]); 46 | IN = mxGetData(prhs[1]); 47 | 48 | if (!strcmp(action,"D")) { 49 | 50 | /* Decompress data */ 51 | OUT = tinfl_decompress_mem_to_heap(IN, INlen, &OUTlen, TINFL_FLAG_PARSE_ZLIB_HEADER); 52 | 53 | if (OUT == NULL) 54 | mexErrMsgTxt("Error when decompressing data."); 55 | } 56 | else if (!strcmp(action,"C")) { 57 | /* Compress data */ 58 | OUT = tdefl_compress_mem_to_heap(IN, INlen, &OUTlen, TDEFL_WRITE_ZLIB_HEADER); 59 | 60 | if (OUT == NULL) 61 | mexErrMsgTxt("Error when compressing data."); 62 | } 63 | else { 64 | mexErrMsgTxt("Unknown ACTION type."); 65 | } 66 | 67 | /* */ 68 | plhs[0] = mxCreateNumericMatrix(OUTlen,1,mxUINT8_CLASS,mxREAL); 69 | if (plhs[0] == NULL) 70 | mexErrMsgTxt("Error when creating output variable."); 71 | 72 | memcpy(mxGetData(plhs[0]), OUT, OUTlen); 73 | 74 | mxFree(action); 75 | mz_free(OUT); 76 | 77 | } 78 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/private/zstream.m: -------------------------------------------------------------------------------- 1 | function Z = zstream(action,D) 2 | % Compress/decompress stream of bytes using Deflate/Inflate 3 | % FORMAT Z = zstream('C',D) 4 | % D - data stream to compress (converted to uint8 if needed) 5 | % Z - compressed data stream (uint8 vector) 6 | % FORMAT D = zstream('D',Z) 7 | % Z - data stream to decompress (uint8 vector) 8 | % D - decompressed data stream (uint8 vector) 9 | %__________________________________________________________________________ 10 | % 11 | % This C-MEX file relies on: 12 | % * miniz, by Rich Geldreich 13 | % http://code.google.com/p/miniz/ 14 | % Fallback Java implementation is adapted from: 15 | % * dzip/dunzip, by Michael Kleder 16 | % http://www.mathworks.com/matlabcentral/fileexchange/8899 17 | %__________________________________________________________________________ 18 | % Copyright (C) 2015 Wellcome Trust Centre for Neuroimaging 19 | 20 | % Guillaume Flandin 21 | % $Id: zstream.m 6417 2015-04-21 16:03:44Z guillaume $ 22 | 23 | 24 | if exist('OCTAVE_VERSION','builtin') 25 | error('zstream.c not compiled - see Makefile'); 26 | end 27 | 28 | switch upper(action) 29 | case 'C' 30 | D = typecast(D(:),'uint8'); 31 | f = java.io.ByteArrayOutputStream(); 32 | g = java.util.zip.DeflaterOutputStream(f); 33 | g.write(D); 34 | g.close; 35 | Z = typecast(f.toByteArray,'uint8'); 36 | f.close; 37 | 38 | case 'D' 39 | import com.mathworks.mlwidgets.io.InterruptibleStreamCopier 40 | a = java.io.ByteArrayInputStream(D); 41 | b = java.util.zip.InflaterInputStream(a); 42 | isc = InterruptibleStreamCopier.getInterruptibleStreamCopier; 43 | c = java.io.ByteArrayOutputStream; 44 | isc.copyStream(b,c); 45 | Z = c.toByteArray; 46 | 47 | otherwise 48 | error('Unknown action "%s".',action); 49 | end 50 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/struct.m: -------------------------------------------------------------------------------- 1 | function s = struct(this) 2 | % Struct method for GIfTI objects 3 | % FORMAT s = struct(this) 4 | % this - GIfTI object 5 | % s - a structure containing public fields of the object 6 | %__________________________________________________________________________ 7 | % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging 8 | 9 | % Guillaume Flandin 10 | % $Id: struct.m 6507 2015-07-24 16:48:02Z guillaume $ 11 | 12 | names = fieldnames(this); 13 | values = cell(length(names), length(this(:))); 14 | 15 | for i=1:length(names) 16 | [values{i,:}] = subsref(this(:), substruct('.',names{i})); 17 | end 18 | s = reshape(cell2struct(values,names,1),size(this)); 19 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@gifti/subsref.m: -------------------------------------------------------------------------------- 1 | function varargout = subsref(this,subs) 2 | % Subscript referencing for GIfTI objects 3 | %__________________________________________________________________________ 4 | % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging 5 | 6 | % Guillaume Flandin 7 | % $Id: subsref.m 6345 2015-02-20 12:25:50Z guillaume $ 8 | 9 | if length(this) > 1 && ~strcmp(subs(1).type,'()') 10 | warning('Not implemented.'); 11 | for i=1:numel(this) 12 | varargout{i} = subsref(this(i),subs); 13 | end 14 | return; 15 | end 16 | 17 | switch subs(1).type 18 | case '.' 19 | [i,j] = isintent(this,subs(1).subs); 20 | if isempty(i) 21 | if strcmp(subs(1).subs,'private') 22 | varargout{1} = builtin('struct',this); 23 | else 24 | error('Reference to non-existent field ''%s''.',subs(1).subs); 25 | end 26 | else 27 | if strcmp(subs(1).subs,'mat') 28 | varargout{1} = this.data{j}.space.MatrixData; 29 | elseif strcmp(subs(1).subs,'labels') 30 | varargout{1} = this.label; 31 | else 32 | if length(j) == 1 33 | varargout{1} = this.data{j}.data; 34 | else 35 | a = [this.data{j}]; 36 | try 37 | varargout{1} = [a.data]; 38 | catch 39 | error('Data arrays are of different sizes.'); 40 | end 41 | end 42 | end 43 | end 44 | if strcmp(subs(1).subs,'faces') || strcmp(subs(1).subs,'indices') 45 | varargout{1} = varargout{1} + 1; % indices start at 1 46 | end 47 | if length(subs) > 1 48 | varargout{1} = subsref(varargout{1},subs(2:end)); 49 | end 50 | case '{}' 51 | error('Cell contents reference from a non-cell array object.'); 52 | case '()' 53 | if length(subs) == 1 54 | varargout{1} = builtin('subsref',this,subs(1)); 55 | else 56 | varargout{1} = subsref(builtin('subsref',this,subs(1)),subs(2:end)); 57 | end 58 | otherwise 59 | error('This should not happen.'); 60 | end -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/Contents.m: -------------------------------------------------------------------------------- 1 | % XMLTree: XML Toolbox for MATLAB and GNU Octave 2 | % Version 2.0 14-Aug-2015 3 | % 4 | % XML file I/O. 5 | % xmltree - Constructor (XML parser). 6 | % save - Save an XMLTree in a file. 7 | % 8 | % XML Tree manipulation methods. 9 | % add - Add a node in a tree. 10 | % attributes - Handle attributes of a node. 11 | % branch - Extract a subtree from a tree. 12 | % children - Return children of a node. 13 | % convert - Convert a tree in a MATLAB structure. 14 | % copy - Copy nodes within a tree. 15 | % delete - Delete a node in a tree. 16 | % find - Find nodes in a tree. 17 | % flush - Clear a subtree. 18 | % get - get node properties. 19 | % getfilename - Get filename. 20 | % isfield - Return true if a field is present in a node. 21 | % length - Return the length of a tree. 22 | % move - Move a node within a tree. 23 | % parent - Return parents of a node. 24 | % root - Return the root element of a tree. 25 | % set - Set node properties. 26 | % setfilename - Set filename. 27 | % 28 | % Graphical user interface methods (basic). 29 | % editor - Graphical display of a tree. 30 | % 31 | % Low level class methods. 32 | % char - Convert a tree into a string (for display). 33 | % display - Display a tree in the workspace. 34 | % 35 | % Private methods. 36 | % xml_parser - XML parser. 37 | % xml_findstr - Find one string within another (C-MEX file). 38 | % 39 | % Conversions struct <=> XML. 40 | % loadxml - 41 | % savexml - 42 | % mat2xml - 43 | % xml2mat - 44 | % struct2xml - 45 | % 46 | % Demos. 47 | % xmldemo1 - Create an XML tree from scratch and save it. 48 | % xmldemo2 - Read an XML file and access fields. 49 | % xmldemo3 - Read an XML file, modify some fields and save it. 50 | 51 | % Copyright 2002-2015 http://www.artefact.tk/ 52 | 53 | % Guillaume Flandin 54 | % $Id: Contents.m 6480 2015-06-13 01:08:30Z guillaume $ 55 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/add.m: -------------------------------------------------------------------------------- 1 | function varargout = add(tree,uid,type,parameter) 2 | % XMLTREE/ADD Method (add childs to elements of an XML Tree) 3 | % FORMAT vararout = add(tree,uid,type,parameter) 4 | % 5 | % tree - XMLTree object 6 | % uid - array of uid's 7 | % type - 'element', 'chardata', 'cdata', 'pi' or 'comment' 8 | % parameter - property name (a character array unless type='pi' for 9 | % which parameter=struct('target','','value','')) 10 | % 11 | % new_uid - UID's of the newly created nodes 12 | % 13 | % tree = add(tree,uid,type,parameter); 14 | % [tree, new_uid] = add(tree,uid,type,parameter); 15 | %__________________________________________________________________________ 16 | % 17 | % Add a node (element, chardata, cdata, pi or comment) in the XML Tree. 18 | % It adds a child to the element whose UID is iud. 19 | % Use attributes({'set','get','add','del','length'},...) function to 20 | % deal with the attributes of an element node (initialized empty). 21 | % The tree parameter must be in input AND in output. 22 | %__________________________________________________________________________ 23 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 24 | 25 | % Guillaume Flandin 26 | % $Id: add.m 4460 2011-09-05 14:52:16Z guillaume $ 27 | 28 | 29 | if ~isa(uid,'double') 30 | error('[XMLTree] UID must be a double array.'); 31 | end 32 | if ~ischar(type) 33 | error('[XMLTree] TYPE must be a valid item type.'); 34 | end 35 | if strcmp(type,'pi') 36 | if ~isfield(parameter,'target') || ~isfield(parameter,'value') || ... 37 | ~ischar(parameter.target) || ~ischar(parameter.value) 38 | error(['[XMLTree] For a Processing Instruction, ',... 39 | 'PARAMETER must be a struct.']); 40 | end 41 | elseif ~ischar(parameter) 42 | error('[XMLTree] PARAMETER must be a string.'); 43 | end 44 | 45 | if nargout == 2 46 | l = length(tree.tree); 47 | varargout{2} = (l+1):(l+numel(uid)); 48 | end 49 | 50 | for i=1:numel(uid) 51 | if uid(i)<1 || uid(i)>length(tree.tree) 52 | error('[XMLTree] Invalid UID.'); 53 | end 54 | if ~strcmp(tree.tree{uid(i)}.type,'element') 55 | error('[XMLTree] Cannot add a child to a non-element node.'); 56 | end 57 | l = length(tree.tree); 58 | switch type 59 | case 'element' 60 | tree.tree{l+1} = struct('type','element',... 61 | 'name',parameter,... 62 | 'attributes',[],... 63 | 'contents',[],... 64 | 'parent',[],... 65 | 'uid',l+1); 66 | case 'chardata' 67 | tree.tree{l+1} = struct('type','chardata',... 68 | 'value',parameter,... 69 | 'parent',[],... 70 | 'uid',l+1); 71 | case 'cdata' 72 | tree.tree{l+1} = struct('type','cdata',... 73 | 'value',parameter,... 74 | 'parent',[],... 75 | 'uid',l+1); 76 | case 'pi' 77 | tree.tree{l+1} = struct('type','pi',... 78 | 'target',parameter.target,... 79 | 'value',parameter.value,... 80 | 'parent',[],... 81 | 'uid',l+1); 82 | case 'comment' 83 | tree.tree{l+1} = struct('type','comment',... 84 | 'value',parameter,... 85 | 'parent',[],... 86 | 'uid',l+1); 87 | otherwise 88 | error(sprintf('[XMLTree] %s: unknown item type.',type)); 89 | end 90 | tree.tree{uid(i)}.contents = [tree.tree{uid(i)}.contents l+1]; 91 | tree.tree{l+1}.parent = uid(i); 92 | end 93 | 94 | varargout{1} = tree; 95 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/attributes.m: -------------------------------------------------------------------------------- 1 | function varargout = attributes(varargin) 2 | % XMLTREE/ATTRIBUTES Method (handle attributes of an element node) 3 | % FORMAT varargout = attributes(varargin) 4 | % 5 | % tree - XMLTree object 6 | % method - 'set','get','add','del' or 'length' 7 | % uid - the UID of an element node 8 | % n - indice of the attribute 9 | % key - string key="..." 10 | % val - string ...="val" 11 | % attr - cell array of struct(key,val) or just struct(key,val) 12 | % l - number of attributes of the element node uid 13 | % 14 | % tree = attributes(tree,'set',uid,n,key,val) 15 | % attr = attributes(tree,'get',uid[,n]) 16 | % tree = attributes(tree,'add',uid,key,val) 17 | % tree = attributes(tree,'del',uid[,n]) 18 | % l = attributes(tree,'length',uid) 19 | %__________________________________________________________________________ 20 | % 21 | % Handle attributes of an element node. 22 | % The tree parameter must be in input AND in output for 'set', 'add' and 23 | % 'del' methods. 24 | %__________________________________________________________________________ 25 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 26 | 27 | % Guillaume Flandin 28 | % $Id: attributes.m 4460 2011-09-05 14:52:16Z guillaume $ 29 | 30 | 31 | %error(nargchk(3,6,nargin)); 32 | 33 | tree = varargin{1}; 34 | if ~ischar(varargin{2}) || ... 35 | ~any(strcmp(varargin{2},{'set','get','add','del','length'})) 36 | error('[XMLTree] Unknown method.'); 37 | end 38 | uid = varargin{3}; 39 | if ~isa(uid,'double') || any(uid>length(tree)) || any(uid<1) 40 | error('[XMLTree] UID must be a positive integer scalar.'); 41 | end 42 | 43 | if ~strcmp(tree.tree{uid}.type,'element') 44 | error('[XMLTree] This node has no attributes.'); 45 | end 46 | 47 | switch varargin{2} 48 | case 'set' 49 | %error(nargchk(6,6,nargin)); 50 | if ~isa(varargin{4},'double') || ... 51 | any(varargin{4}>length(tree.tree{uid}.attributes)) || ... 52 | any(varargin{4}<1) 53 | error('[XMLTree] Invalid attribute indice.'); 54 | end 55 | ind = varargin{4}; 56 | tree.tree{uid}.attributes{ind} = struct('key',varargin{5},'val',varargin{6}); 57 | varargout{1} = tree; 58 | case 'get' 59 | %error(nargchk(3,4,nargin)); 60 | if nargin == 4 61 | if ischar(varargin{4}) 62 | for i=1:length(tree.tree{uid}.attributes) 63 | if strcmp(varargin{4},tree.tree{uid}.attributes{i}.key) 64 | varargout{1} = tree.tree{uid}.attributes{i}.val; 65 | return; 66 | end 67 | end 68 | varargout{1} = []; 69 | elseif ~isa(varargin{4},'double') || ... 70 | any(varargin{4}>length(tree.tree{uid}.attributes)) || ... 71 | any(varargin{4}<1) 72 | error('[XMLTree] Invalid attribute indice.'); 73 | else 74 | if length(varargin{4}) == 1 75 | varargout{1} = tree.tree{uid}.attributes{varargin{4}(1)}; 76 | else 77 | varargout{1} = {}; 78 | for i=1:length(varargin{4}) 79 | varargout{1}{i} = tree.tree{uid}.attributes{varargin{4}(i)}; 80 | end 81 | end 82 | end 83 | else 84 | if length(tree.tree{uid}.attributes) == 1 85 | varargout{1} = tree.tree{uid}.attributes{1}; 86 | else 87 | varargout{1} = {}; 88 | for i=1:length(tree.tree{uid}.attributes) 89 | varargout{1}{i} = tree.tree{uid}.attributes{i}; 90 | end 91 | end 92 | end 93 | case 'add' 94 | %error(nargchk(5,5,nargin)); 95 | ind = length(tree.tree{uid}.attributes) + 1; 96 | tree.tree{uid}.attributes{ind} = struct('key',varargin{4},'val',varargin{5}); 97 | varargout{1} = tree; 98 | case 'del' 99 | %error(nargchk(3,4,nargin)); 100 | if nargin == 4 101 | if ~isa(varargin{4},'double') || ... 102 | any(varargin{4}>length(tree.tree{uid}.attributes)) || ... 103 | any(varargin{4}<1) 104 | error('[XMLTree] Invalid attribute indice.'); 105 | end 106 | ind = varargin{4}; 107 | tree.tree{uid}.attributes(ind) = []; 108 | else 109 | tree.tree{uid}.attributes = []; 110 | end 111 | varargout{1} = tree; 112 | case 'length' 113 | %error(nargchk(3,3,nargin)); 114 | varargout{1} = length(tree.tree{uid}.attributes); 115 | otherwise 116 | error('[XMLTree] Unknown method.'); 117 | end 118 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/branch.m: -------------------------------------------------------------------------------- 1 | function subtree = branch(tree,uid) 2 | % XMLTREE/BRANCH Branch Method 3 | % FORMAT uid = parent(tree,uid) 4 | % 5 | % tree - XMLTree object 6 | % uid - UID of the root element of the subtree 7 | % subtree - XMLTree object (a subtree from tree) 8 | %__________________________________________________________________________ 9 | % 10 | % Return a subtree from a tree. 11 | %__________________________________________________________________________ 12 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 13 | 14 | % Guillaume Flandin 15 | % $Id: branch.m 4460 2011-09-05 14:52:16Z guillaume $ 16 | 17 | 18 | %error(nargchk(2,2,nargin)); 19 | 20 | if uid > length(tree) || ... 21 | numel(uid)~=1 || ... 22 | ~strcmp(tree.tree{uid}.type,'element') 23 | error('[XMLTree] Invalid UID.'); 24 | end 25 | 26 | subtree = xmltree; 27 | subtree = set(subtree,root(subtree),'name',tree.tree{uid}.name); 28 | %- fix by Piotr Dollar to copy attributes for the root node: 29 | subtree = set(subtree,root(subtree),'attributes',tree.tree{uid}.attributes); 30 | 31 | child = children(tree,uid); 32 | 33 | for i=1:length(child) 34 | l = length(subtree); 35 | subtree = sub_branch(tree,subtree,child(i),root(subtree)); 36 | subtree.tree{root(subtree)}.contents = [subtree.tree{root(subtree)}.contents l+1]; 37 | end 38 | 39 | %========================================================================== 40 | function tree = sub_branch(t,tree,uid,p) 41 | 42 | l = length(tree); 43 | tree.tree{l+1} = t.tree{uid}; 44 | tree.tree{l+1}.uid = l + 1; 45 | tree.tree{l+1}.parent = p; 46 | tree.tree{l+1}.contents = []; 47 | if isfield(t.tree{uid},'contents') 48 | contents = get(t,uid,'contents'); 49 | m = length(tree); 50 | for i=1:length(contents) 51 | tree.tree{l+1}.contents = [tree.tree{l+1}.contents m+1]; 52 | tree = sub_branch(t,tree,contents(i),l+1); 53 | m = length(tree); 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/char.m: -------------------------------------------------------------------------------- 1 | function s = char(tree) 2 | % XMLTREE/CHAR Converter function from XMLTree to a description string 3 | % FORMAT s = char(tree) 4 | % 5 | % tree - XMLTree object 6 | % s - a description string of an XMLTree 7 | %__________________________________________________________________________ 8 | % 9 | % Return a string describing the XMLTree: 10 | % 'XMLTree object (x nodes) [filename]' 11 | %__________________________________________________________________________ 12 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 13 | 14 | % Guillaume Flandin 15 | % $Id: char.m 4460 2011-09-05 14:52:16Z guillaume $ 16 | 17 | 18 | s = strcat('XMLTree object (',num2str(length(tree)),' nodes) [',getfilename(tree),']'); 19 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/children.m: -------------------------------------------------------------------------------- 1 | function child = children(tree,uid) 2 | % XMLTREE/CHILDREN Return children's UIDs of node uid 3 | % FORMAT child = children(tree,uid) 4 | % 5 | % tree - a tree 6 | % uid - uid of the element 7 | % child - array of the UIDs of children of node uid 8 | %__________________________________________________________________________ 9 | % 10 | % Return UID's of children of node uid 11 | %__________________________________________________________________________ 12 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 13 | 14 | % Guillaume Flandin 15 | % $Id: children.m 4460 2011-09-05 14:52:16Z guillaume $ 16 | 17 | %error(nargchk(2,2,nargin)); 18 | 19 | child = []; 20 | uid = uid(:); 21 | l = length(tree); 22 | for i=1:length(uid) 23 | if uid(i) > 0 && uid(i) <= l 24 | if strcmp(tree.tree{uid(i)}.type,'element') 25 | child = [child tree.tree{uid(i)}.contents]; 26 | end 27 | else 28 | error('[XMLTree] Invalid UID.'); 29 | end 30 | end 31 | if isempty(child), child = []; end 32 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/copy.m: -------------------------------------------------------------------------------- 1 | function tree = copy(tree,subuid,uid) 2 | % XMLTREE/COPY Copy Method (copy a subtree in another branch) 3 | % FORMAT tree = copy(tree,subuid,uid) 4 | % 5 | % tree - XMLTree object 6 | % subuid - UID of the subtree to copy 7 | % uid - UID of the element where the subtree must be duplicated 8 | %__________________________________________________________________________ 9 | % 10 | % Copy a subtree to another branch. 11 | % The tree parameter must be in input AND in output. 12 | %__________________________________________________________________________ 13 | % Copyright (C) 2002-2015 http://www.artefact.tk/ 14 | 15 | % Guillaume Flandin 16 | % $Id: copy.m 6480 2015-06-13 01:08:30Z guillaume $ 17 | 18 | 19 | %error(nargchk(2,3,nargin)); 20 | 21 | if nargin == 2 22 | uid = parent(tree,subuid); 23 | end 24 | 25 | l = length(tree); 26 | tree = sub_copy(tree,subuid,uid); 27 | tree.tree{uid}.contents = [tree.tree{uid}.contents l+1]; 28 | 29 | % to have the copy next to the original and not at the end? 30 | % contents = get(tree,parent,'contents'); 31 | % i = find(contents==uid); 32 | % tree = set(tree,parent,'contents',[contents(1:i) l+1 contents(i+1:end)]); 33 | 34 | %========================================================================== 35 | function tree = sub_copy(tree,uid,p) 36 | 37 | l = length(tree); 38 | tree.tree{l+1} = tree.tree{uid}; 39 | tree.tree{l+1}.uid = l+1; 40 | tree.tree{l+1}.parent = p; 41 | tree.tree{l+1}.contents = []; 42 | if isfield(tree.tree{uid},'contents') 43 | contents = get(tree,uid,'contents'); 44 | m = length(tree); 45 | for i=1:length(contents) 46 | tree.tree{l+1}.contents = [tree.tree{l+1}.contents m+1]; 47 | tree = sub_copy(tree,contents(i),l+1); 48 | m = length(tree); 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/delete.m: -------------------------------------------------------------------------------- 1 | function tree = delete(tree,uid) 2 | % XMLTREE/DELETE Delete (delete a subtree given its UID) 3 | % 4 | % tree - XMLTree object 5 | % uid - array of UID's of subtrees to be deleted 6 | %__________________________________________________________________________ 7 | % 8 | % Delete a subtree given its UID 9 | % The tree parameter must be in input AND in output 10 | %__________________________________________________________________________ 11 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 12 | 13 | % Guillaume Flandin 14 | % $Id: delete.m 4460 2011-09-05 14:52:16Z guillaume $ 15 | 16 | %error(nargchk(2,2,nargin)); 17 | 18 | uid = uid(:); 19 | for i=1:length(uid) 20 | if uid(i)==1 21 | warning('[XMLTree] Cannot delete root element.'); 22 | else 23 | p = tree.tree{uid(i)}.parent; 24 | tree = sub_delete(tree,uid(i)); 25 | tree.tree{p}.contents(find(tree.tree{p}.contents==uid(i))) = []; 26 | end 27 | end 28 | 29 | %========================================================================== 30 | function tree = sub_delete(tree,uid) 31 | if isfield(tree.tree{uid},'contents') 32 | for i=1:length(tree.tree{uid}.contents) 33 | tree = sub_delete(tree,tree.tree{uid}.contents(i)); 34 | end 35 | end 36 | tree.tree{uid} = struct('type','deleted'); 37 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/display.m: -------------------------------------------------------------------------------- 1 | function display(tree) 2 | % XMLTREE/DISPLAY Command window display of an XMLTree 3 | % FORMAT display(tree) 4 | % 5 | % tree - XMLTree object 6 | %__________________________________________________________________________ 7 | % 8 | % This method is called when the semicolon is not used to terminate a 9 | % statement which returns an XMLTree. 10 | %__________________________________________________________________________ 11 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 12 | 13 | % Guillaume Flandin 14 | % $Id: display.m 4460 2011-09-05 14:52:16Z guillaume $ 15 | 16 | disp(' '); 17 | disp([inputname(1),' = ']); 18 | disp(' '); 19 | for i=1:numel(tree) 20 | disp([blanks(length(inputname(1))+3) char(tree(i))]); 21 | end 22 | disp(' '); 23 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/flush.m: -------------------------------------------------------------------------------- 1 | function tree = flush(tree,uid) 2 | % XMLTREE/FLUSH Flush (Clear a subtree given its UID) 3 | % 4 | % tree - XMLTree object 5 | % uid - array of UID's of subtrees to be cleared 6 | % Default is root 7 | %__________________________________________________________________________ 8 | % 9 | % Clear a subtree given its UID (remove all the leaves of the tree) 10 | % The tree parameter must be in input AND in output 11 | %__________________________________________________________________________ 12 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 13 | 14 | % Guillaume Flandin 15 | % $Id: flush.m 4460 2011-09-05 14:52:16Z guillaume $ 16 | 17 | 18 | %error(nargchk(1,2,nargin)); 19 | 20 | if nargin == 1, 21 | uid = root(tree); 22 | end 23 | 24 | uid = uid(:); 25 | for i=1:length(uid) 26 | tree = sub_flush(tree,uid(i)); 27 | end 28 | 29 | %========================================================================== 30 | function tree = sub_flush(tree,uid) 31 | if isfield(tree.tree{uid},'contents') 32 | % contents is parsed in reverse order because each child is 33 | % deleted and the contents vector is then eventually reduced 34 | for i=length(tree.tree{uid}.contents):-1:1 35 | tree = sub_flush(tree,tree.tree{uid}.contents(i)); 36 | end 37 | end 38 | if strcmp(tree.tree{uid}.type,'chardata') ||... 39 | strcmp(tree.tree{uid}.type,'pi') ||... 40 | strcmp(tree.tree{uid}.type,'cdata') ||... 41 | strcmp(tree.tree{uid}.type,'comment') 42 | tree = delete(tree,uid); 43 | end 44 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/get.m: -------------------------------------------------------------------------------- 1 | function value = get(tree,uid,parameter) 2 | % XMLTREE/GET Get Method (get object properties) 3 | % FORMAT value = get(tree,uid,parameter) 4 | % 5 | % tree - XMLTree object 6 | % uid - array of uid's 7 | % parameter - property name 8 | % value - property value 9 | %__________________________________________________________________________ 10 | % 11 | % Get object properties of a tree given their UIDs. 12 | %__________________________________________________________________________ 13 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 14 | 15 | % Guillaume Flandin 16 | % $Id: get.m 4460 2011-09-05 14:52:16Z guillaume $ 17 | 18 | 19 | %error(nargchk(2,3,nargin)); 20 | 21 | value = cell(size(uid)); 22 | uid = uid(:); 23 | if nargin==2 24 | for i=1:length(uid) 25 | if uid(i)<1 || uid(i)>length(tree.tree) 26 | error('[XMLTree] Invalid UID.'); 27 | end 28 | % According to the type of the node, return only some parameters 29 | % Need changes... 30 | value{i} = tree.tree{uid(i)}; 31 | end 32 | else 33 | for i=1:length(uid) 34 | try 35 | value{i} = subsref(tree.tree{uid(i)}, struct('type','.','subs',parameter)); 36 | catch 37 | error(sprintf('[XMLTree] Parameter %s not found.',parameter)); 38 | end 39 | end 40 | end 41 | if length(value)==1 42 | value = value{1}; 43 | end 44 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/getfilename.m: -------------------------------------------------------------------------------- 1 | function filename = getfilename(tree) 2 | % XMLTREE/GETFILENAME Get filename method 3 | % FORMAT filename = getfilename(tree) 4 | % 5 | % tree - XMLTree object 6 | % filename - XML filename 7 | %__________________________________________________________________________ 8 | % 9 | % Return the filename of the XML tree if loaded from disk and an empty 10 | % string otherwise. 11 | %__________________________________________________________________________ 12 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 13 | 14 | % Guillaume Flandin 15 | % $Id: getfilename.m 4460 2011-09-05 14:52:16Z guillaume $ 16 | 17 | filename = tree.filename; 18 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/isfield.m: -------------------------------------------------------------------------------- 1 | function F = isfield(tree,uid,parameter) 2 | % XMLTREE/ISFIELD Is parameter a field of tree{uid} ? 3 | % FORMAT F = isfield(tree,uid,parameter) 4 | % 5 | % tree - a tree 6 | % uid - uid of the element 7 | % parameter - a field of the root tree 8 | % F - 1 if present, 0 otherwise 9 | %__________________________________________________________________________ 10 | % 11 | % Is parameter a field of tree{uid} ? 12 | %__________________________________________________________________________ 13 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 14 | 15 | % Guillaume Flandin 16 | % $Id: isfield.m 4460 2011-09-05 14:52:16Z guillaume $ 17 | 18 | 19 | %error(nargchk(3,3,nargin)); 20 | 21 | F = zeros(1,length(uid)); 22 | for i=1:length(uid) 23 | if isfield(tree.tree{uid(i)},parameter) 24 | F(i) = 1; 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/length.m: -------------------------------------------------------------------------------- 1 | function l = length(tree,r) 2 | % XMLTREE/LENGTH Length Method 3 | % FORMAT l = length(tree,r) 4 | % 5 | % tree - XMLTree object 6 | % r - 'real' if present, returns the real number of nodes in the 7 | % tree (deleted nodes aren't populated) 8 | % l - length of the XML tree (number of nodes) 9 | %__________________________________________________________________________ 10 | % 11 | % Return the number of nodes of an XMLTree object. 12 | %__________________________________________________________________________ 13 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 14 | 15 | % Guillaume Flandin 16 | % $Id: length.m 4460 2011-09-05 14:52:16Z guillaume $ 17 | 18 | 19 | %error(nargchk(1,2,nargin)); 20 | 21 | % Return the full number of nodes once allocated 22 | l = length(tree.tree); 23 | 24 | % Substract the number of deleted nodes to the previous length 25 | if nargin == 2 26 | if strcmp(r,'real') 27 | ll = 0; 28 | for i=1:l 29 | if ~strcmp(tree.tree{i}.type,'deleted') 30 | ll = ll + 1; 31 | end 32 | end 33 | l = ll; 34 | else 35 | error('[XMLTree] Bad input argument.'); 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/move.m: -------------------------------------------------------------------------------- 1 | function tree = move(tree,uida, uidb) 2 | % XMLTREE/MOVE Move (move a subtree inside a tree from A to B) 3 | % 4 | % tree - XMLTree object 5 | % uida - initial position of the subtree 6 | % uidb - parent of the final position of the subtree 7 | %__________________________________________________________________________ 8 | % 9 | % Move a subtree inside a tree from A to B. 10 | % The tree parameter must be in input AND in output. 11 | %__________________________________________________________________________ 12 | % Copyright (C) 2002-2015 http://www.artefact.tk/ 13 | 14 | % Guillaume Flandin 15 | % $Id: move.m 6480 2015-06-13 01:08:30Z guillaume $ 16 | 17 | 18 | %error(nargchk(3,3,nargin)); 19 | 20 | p = tree.tree{uida}.parent; 21 | tree.tree{p}.contents(find(tree.tree{p}.contents==uida)) = []; 22 | tree.tree(uidb).contents = [tree.tree(uidb).contents uida]; 23 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/parent.m: -------------------------------------------------------------------------------- 1 | function p = parent(tree,uid) 2 | % XMLTREE/PARENT Parent Method 3 | % FORMAT uid = parent(tree,uid) 4 | % 5 | % tree - XMLTree object 6 | % uid - UID of the lonely child 7 | % p - UID of the parent ([] if root is the child) 8 | %__________________________________________________________________________ 9 | % 10 | % Return the uid of the parent of a node. 11 | %__________________________________________________________________________ 12 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 13 | 14 | % Guillaume Flandin 15 | % $Id: parent.m 4460 2011-09-05 14:52:16Z guillaume $ 16 | 17 | p = tree.tree{uid}.parent; 18 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/private/xml_findstr.c: -------------------------------------------------------------------------------- 1 | #include "mex.h" 2 | 3 | /* 4 | * $Id: xml_findstr.c 6480 2015-06-13 01:08:30Z guillaume $ 5 | * Guillaume Flandin 6 | */ 7 | 8 | /* 9 | Differences with built-in findstr: 10 | - allows to search only the n first occurences of a pattern 11 | - allows to search only in a substring (given an index of the beginning) 12 | 13 | MATLAB hack: 14 | - doesn't use mxGetString to prevent a copy of the string. 15 | - assumes MATLAB stores strings as unsigned short (Unicode 16 bits) 16 | matrix.h: typedef uint16_T mxChar; 17 | (that's the case for MATLAB 5.*, 6.* and 7.* but MATLAB 4.* stores 18 | strings as double and GNU Octave as char, see src/mxarray.h) 19 | */ 20 | 21 | /* Comment the following line to use standard mxGetString (slower) */ 22 | #if !defined (HAVE_OCTAVE) 23 | #define __HACK_MXCHAR__ 24 | #endif 25 | 26 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { 27 | 28 | unsigned int i, j, stext, spattern, nbmatch = 0, ind = 1, occur = 0, nboccur = 0; 29 | #ifdef __HACK_MXCHAR__ 30 | unsigned short int *text = NULL, *pattern = NULL; 31 | #else 32 | char *text = NULL, *pattern = NULL; 33 | #endif 34 | unsigned int *k = NULL; 35 | mxArray *out = NULL; 36 | 37 | /* Check for proper number of arguments. */ 38 | if ((nrhs == 0) || (nrhs == 1)) 39 | mexErrMsgTxt("Not enough input arguments."); 40 | else if (nrhs > 4) 41 | mexErrMsgTxt("Too many input arguments."); 42 | else if (nlhs > 1) 43 | mexErrMsgTxt("Too many output arguments."); 44 | 45 | /* The input TEXT must be a string */ 46 | if (!mxIsChar(prhs[0])) 47 | mexErrMsgTxt("Inputs must be character arrays."); 48 | stext = mxGetM(prhs[0]) * mxGetN(prhs[0]); 49 | #ifdef __HACK_MXCHAR__ 50 | text = mxGetData(prhs[0]); 51 | #else 52 | text = mxCalloc(stext+1, sizeof(char)); 53 | mxGetString(prhs[0], text, stext+1); 54 | #endif 55 | 56 | /* The input PATTERN must be a string */ 57 | if (!mxIsChar(prhs[1])) 58 | mexErrMsgTxt("Inputs must be character arrays."); 59 | spattern = mxGetM(prhs[1]) * mxGetN(prhs[1]); 60 | #ifdef __HACK_MXCHAR__ 61 | pattern = mxGetData(prhs[1]); 62 | #else 63 | pattern = mxCalloc(spattern+1, sizeof(char)); 64 | mxGetString(prhs[1], pattern, spattern+1); 65 | #endif 66 | 67 | /* The input INDEX must be an integer */ 68 | if (nrhs > 2) { 69 | if ((!mxIsNumeric(prhs[2]) || (mxGetM(prhs[2]) * mxGetN(prhs[2]) != 1))) 70 | mexErrMsgTxt("Index input must be an integer."); 71 | ind = (unsigned int)mxGetScalar(prhs[2]); 72 | if (ind < 1) 73 | mexErrMsgTxt("Index must be greater than 1."); 74 | } 75 | 76 | /* The input OCCUR must be an integer */ 77 | if (nrhs == 4) { 78 | if ((!mxIsNumeric(prhs[3]) || (mxGetM(prhs[3]) * mxGetN(prhs[3]) != 1))) 79 | mexErrMsgTxt("Index input must be an integer."); 80 | nboccur = (unsigned int)mxGetScalar(prhs[3]); 81 | } 82 | 83 | /* Find pattern in text */ 84 | for (i=ind-1;i=i); 42 | if ~isempty(k), k = k(1:min(n,length(k))); end 43 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/private/xml_findstr.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/cifti-matlab-master/@xmltree/private/xml_findstr.mexa64 -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/private/xml_findstr.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/cifti-matlab-master/@xmltree/private/xml_findstr.mexglx -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/private/xml_findstr.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/cifti-matlab-master/@xmltree/private/xml_findstr.mexmaci -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/private/xml_findstr.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/cifti-matlab-master/@xmltree/private/xml_findstr.mexmaci64 -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/private/xml_findstr.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/cifti-matlab-master/@xmltree/private/xml_findstr.mexw32 -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/private/xml_findstr.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/cifti-matlab-master/@xmltree/private/xml_findstr.mexw64 -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/root.m: -------------------------------------------------------------------------------- 1 | function uid = root(tree) 2 | % XMLTREE/ROOT Root Method 3 | % FORMAT uid = root(tree) 4 | % 5 | % tree - XMLTree object 6 | % uid - UID of the root element of tree 7 | %__________________________________________________________________________ 8 | % 9 | % Return the uid of the root element of the tree. 10 | %__________________________________________________________________________ 11 | % Copyright (C) 2002-2008 http://www.artefact.tk/ 12 | 13 | % Guillaume Flandin 14 | % $Id: root.m 4460 2011-09-05 14:52:16Z guillaume $ 15 | 16 | % Actually root is necessarily the element whos UID is 1, by 17 | % construction. However, xml_parser should return a tree with a ROOT 18 | % element with as many children as needed but only ONE *element* child 19 | % who would be the real root (and this method should return the UID of 20 | % this element). 21 | 22 | uid = 1; 23 | 24 | % Update: 25 | % xml_parser has been modified (not as explained above) to handle the 26 | % case when several nodes are at the top level of the XML. 27 | % Example: blah blah 28 | % Now root is the first element node of the tree. 29 | 30 | % Look for the first element in the XML Tree 31 | for i=1:length(tree) 32 | if strcmp(get(tree,i,'type'),'element') 33 | uid = i; 34 | break 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/save.m: -------------------------------------------------------------------------------- 1 | function varargout = save(tree, filename) 2 | % XMLTREE/SAVE Save an XML tree in an XML file 3 | % FORMAT varargout = save(tree,filename) 4 | % 5 | % tree - XMLTree 6 | % filename - XML output filename 7 | % varargout - XML string 8 | %__________________________________________________________________________ 9 | % 10 | % Convert an XML tree into a well-formed XML string and write it into 11 | % a file or return it as a string if no filename is provided. 12 | %__________________________________________________________________________ 13 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 14 | 15 | % Guillaume Flandin 16 | % $Id: save.m 4460 2011-09-05 14:52:16Z guillaume $ 17 | 18 | 19 | %error(nargchk(1,2,nargin)); 20 | 21 | prolog = '\n'; 22 | 23 | %- Return the XML tree as a string 24 | if nargin == 1 25 | varargout{1} = [sprintf(prolog) ... 26 | print_subtree(tree,'',root(tree))]; 27 | %- Output specified 28 | else 29 | %- Filename provided 30 | if ischar(filename) 31 | [fid, msg] = fopen(filename,'w'); 32 | if fid==-1, error(msg); end 33 | if isempty(tree.filename), tree.filename = filename; end 34 | %- File identifier provided 35 | elseif isnumeric(filename) && numel(filename) == 1 36 | fid = filename; 37 | prolog = ''; %- With this option, do not write any prolog 38 | else 39 | error('[XMLTree] Invalid argument.'); 40 | end 41 | fprintf(fid,prolog); 42 | save_subtree(tree,fid,root(tree)); 43 | if ischar(filename), fclose(fid); end 44 | if nargout == 1 45 | varargout{1} = print_subtree(tree,'',root(tree)); 46 | end 47 | end 48 | 49 | %========================================================================== 50 | function xmlstr = print_subtree(tree,xmlstr,uid,order) 51 | if nargin < 4, order = 0; end 52 | xmlstr = [xmlstr blanks(3*order)]; 53 | switch tree.tree{uid}.type 54 | case 'element' 55 | xmlstr = sprintf('%s<%s',xmlstr,tree.tree{uid}.name); 56 | for i=1:length(tree.tree{uid}.attributes) 57 | xmlstr = sprintf('%s %s="%s"', xmlstr, ... 58 | tree.tree{uid}.attributes{i}.key,... 59 | tree.tree{uid}.attributes{i}.val); 60 | end 61 | if isempty(tree.tree{uid}.contents) 62 | xmlstr = sprintf('%s/>\n',xmlstr); 63 | else 64 | xmlstr = sprintf('%s>\n',xmlstr); 65 | for i=1:length(tree.tree{uid}.contents) 66 | xmlstr = print_subtree(tree,xmlstr, ... 67 | tree.tree{uid}.contents(i),order+1); 68 | end 69 | xmlstr = [xmlstr blanks(3*order)]; 70 | xmlstr = sprintf('%s\n',xmlstr,... 71 | tree.tree{uid}.name); 72 | end 73 | case 'chardata' 74 | xmlstr = sprintf('%s%s\n',xmlstr, ... 75 | entity(tree.tree{uid}.value)); 76 | case 'cdata' 77 | xmlstr = sprintf('%s\n',xmlstr, ... 78 | tree.tree{uid}.value); 79 | case 'pi' 80 | xmlstr = sprintf('%s\n',xmlstr, ... 81 | tree.tree{uid}.target, tree.tree{uid}.value); 82 | case 'comment' 83 | xmlstr = sprintf('%s\n',xmlstr,... 84 | tree.tree{uid}.value); 85 | otherwise 86 | warning(sprintf('Type %s unknown: not saved', ... 87 | tree.tree{uid}.type)); 88 | end 89 | 90 | %========================================================================== 91 | function save_subtree(tree,fid,uid,order) 92 | if nargin < 4, order = 0; end 93 | fprintf(fid,blanks(3*order)); 94 | switch tree.tree{uid}.type 95 | case 'element' 96 | fprintf(fid,'<%s',tree.tree{uid}.name); 97 | for i=1:length(tree.tree{uid}.attributes) 98 | fprintf(fid,' %s="%s"',... 99 | tree.tree{uid}.attributes{i}.key, ... 100 | tree.tree{uid}.attributes{i}.val); 101 | end 102 | if isempty(tree.tree{uid}.contents) 103 | fprintf(fid,'/>\n'); 104 | else 105 | fprintf(fid,'>\n'); 106 | for i=1:length(tree.tree{uid}.contents) 107 | save_subtree(tree,fid,... 108 | tree.tree{uid}.contents(i),order+1) 109 | end 110 | fprintf(fid,blanks(3*order)); 111 | fprintf(fid,'\n',tree.tree{uid}.name); 112 | end 113 | case 'chardata' 114 | fprintf(fid,'%s\n',entity(tree.tree{uid}.value)); 115 | case 'cdata' 116 | fprintf(fid,'\n',tree.tree{uid}.value); 117 | case 'pi' 118 | fprintf(fid,'\n',tree.tree{uid}.target, ... 119 | tree.tree{uid}.value); 120 | case 'comment' 121 | fprintf(fid,'\n',tree.tree{uid}.value); 122 | otherwise 123 | warning(sprintf('[XMLTree] Type %s unknown: not saved', ... 124 | tree.tree{uid}.type)); 125 | end 126 | 127 | 128 | %========================================================================== 129 | function str = entity(str) 130 | % This has the side effect of strtrim'ming the char array. 131 | str = char(strrep(cellstr(str), '&', '&' )); 132 | str = char(strrep(cellstr(str), '<', '<' )); 133 | str = char(strrep(cellstr(str), '>', '>' )); 134 | str = char(strrep(cellstr(str), '"', '"')); 135 | str = char(strrep(cellstr(str), '''', ''')); 136 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/set.m: -------------------------------------------------------------------------------- 1 | function tree = set(tree,uid, parameter, value) 2 | % XMLTREE/SET Method (set object properties) 3 | % FORMAT tree = set(tree,uid,parameter,value) 4 | % 5 | % tree - XMLTree object 6 | % uid - array (or cell) of uid's 7 | % parameter - property name 8 | % value - property value 9 | %__________________________________________________________________________ 10 | % 11 | % Set object properties given its uid and pairs parameter/value 12 | % The tree parameter must be in input AND in output 13 | %__________________________________________________________________________ 14 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 15 | 16 | % Guillaume Flandin 17 | % $Id: set.m 4460 2011-09-05 14:52:16Z guillaume $ 18 | 19 | 20 | %error(nargchk(4,4,nargin)); 21 | 22 | if iscell(uid), uid = [uid{:}]; else uid = uid(:); end 23 | 24 | for i=1:length(uid) 25 | tree.tree{uid(i)} = builtin('subsasgn', tree.tree{uid(i)}, struct('type','.','subs',parameter), value); 26 | %tree.tree{uid(i)} = setfield(tree.tree{uid(i)},parameter,value); 27 | end 28 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/setfilename.m: -------------------------------------------------------------------------------- 1 | function tree = setfilename(tree,filename) 2 | % XMLTREE/SETFILENAME Set filename method 3 | % FORMAT tree = setfilename(tree,filename) 4 | % 5 | % tree - XMLTree object 6 | % filename - XML filename 7 | %__________________________________________________________________________ 8 | % 9 | % Set the filename linked to the XML tree as filename. 10 | %__________________________________________________________________________ 11 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 12 | 13 | % Guillaume Flandin 14 | % $Id: setfilename.m 4460 2011-09-05 14:52:16Z guillaume $ 15 | 16 | tree.filename = filename; 17 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/@xmltree/xmltree.m: -------------------------------------------------------------------------------- 1 | function tree = xmltree(varargin) 2 | % XMLTREE/XMLTREE Constructor of the XMLTree class 3 | % FORMAT tree = xmltree(varargin) 4 | % 5 | % varargin - XML filename or XML string 6 | % tree - XMLTree Object 7 | % 8 | % tree = xmltree; % creates a minimal XML tree: '' 9 | % tree = xmltree('foo.xml'); % creates a tree from XML file 'foo.xml' 10 | % tree = xmltree('content') % creates a tree from string 11 | %__________________________________________________________________________ 12 | % 13 | % This is the constructor of the XMLTree class. 14 | % It creates a tree of an XML 1.0 file (after parsing) that is stored 15 | % using a Document Object Model (DOM) representation. 16 | % See http://www.w3.org/TR/REC-xml for details about XML 1.0. 17 | % See http://www.w3.org/DOM/ for details about DOM platform. 18 | %__________________________________________________________________________ 19 | % Copyright (C) 2002-2011 http://www.artefact.tk/ 20 | 21 | % Guillaume Flandin 22 | % $Id: xmltree.m 4460 2011-09-05 14:52:16Z guillaume $ 23 | 24 | switch(nargin) 25 | case 0 26 | tree.tree{1} = struct('type','element',... 27 | 'name','tag',... 28 | 'attributes',[],... 29 | 'contents',[],... 30 | 'parent',[],... 31 | 'uid',1); 32 | tree.filename = ''; 33 | tree = class(tree,'xmltree'); 34 | case 1 35 | if isa(varargin{1},'xmltree') 36 | tree = varargin{1}; 37 | elseif ischar(varargin{1}) 38 | % Input argument is an XML string 39 | if (~exist(varargin{1},'file') && ... 40 | ~isempty(xml_findstr(varargin{1},'<',1,1))) 41 | tree.tree = xml_parser(varargin{1}); 42 | tree.filename = ''; 43 | % Input argument is an XML filename 44 | else 45 | fid = fopen(varargin{1},'rt'); 46 | if (fid == -1) 47 | error(['[XMLTree] Cannot open ' varargin{1}]); 48 | end 49 | xmlstr = fread(fid,'*char')'; 50 | %xmlstr = fscanf(fid,'%c'); 51 | fclose(fid); 52 | tree.tree = xml_parser(xmlstr); 53 | tree.filename = varargin{1}; 54 | end 55 | tree = class(tree,'xmltree'); 56 | else 57 | error('[XMLTree] Bad input argument'); 58 | end 59 | otherwise 60 | error('[XMLTree] Too many input arguments'); 61 | end 62 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/LICENSE.fieldtrip: -------------------------------------------------------------------------------- 1 | FieldTrip - the MATLAB toolbox for MEG and EEG analysis 2 | Copyright (C) 2002-2014 by the members of the FieldTrip team 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation Inc, 59 Temple Pl. - Suite 330, Boston, MA 02111-1307, USA. 17 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/LICENSE.gifti: -------------------------------------------------------------------------------- 1 | GIfTI - a MATLAB GIfTI Library 2 | Copyright (C) 2008-2015 Guillaume Flandin 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation Inc, 59 Temple Pl. - Suite 330, Boston, MA 02111-1307, USA. 17 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/LICENSE.xmltree: -------------------------------------------------------------------------------- 1 | XMLTree - an XML toolbox for MATLAB 2 | Copyright (C) 2008 Guillaume Flandin 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation Inc, 59 Temple Pl. - Suite 330, Boston, MA 02111-1307, USA. 17 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/README.md: -------------------------------------------------------------------------------- 1 | MATLAB code for reading and writing CIFTI files 2 | =============================================== 3 | 4 | NOTE: The code available in this repository has known behaviors that are problematic when using fMRI CIFTI data processed with HCP templates. For fMRI CIFTI data, we recommend and provide support for using ciftiopen/ciftisave/ciftisavereset, available at https://wiki.humanconnectome.org/display/PublicData/HCP+Users+FAQ, FAQ #2, option B. 5 | 6 | This repository contains a subset of the MATLAB code from the FieldTrip and 7 | the SPM toolboxes. It should allow MATLAB users and developers to integrate 8 | the CIFTI file format in their analysis pipelines, using the data and tools 9 | of the Human Connectome Project (HCP). 10 | 11 | See http://www.humanconnectome.org for details on the HCP. 12 | 13 | See http://www.nitrc.org/forum/forum.php?forum_id=1955 for details on CIFTI. 14 | 15 | See http://www.fieldtriptoolbox.org for details on FieldTrip. 16 | 17 | See http://www.fil.ion.ucl.ac.uk/spm/ for details on SPM. 18 | 19 | See the LICENSE and GPL files for copyright information. 20 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/VERSION: -------------------------------------------------------------------------------- 1 | Sat Apr 16 08:08:11 UTC 2016 2 | https://github.com/fieldtrip/fieldtrip/commits/d6ada706fdb09f824c38e4de7655757076be4a21 3 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/documentation/CIFTI-2_Appendix_FINAL_1March2014.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/cifti-matlab-master/documentation/CIFTI-2_Appendix_FINAL_1March2014.pdf -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/documentation/CIFTI-2_Main_FINAL_1March2014.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/cifti-matlab-master/documentation/CIFTI-2_Main_FINAL_1March2014.pdf -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/emptyfile.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/copyfields.m: -------------------------------------------------------------------------------- 1 | function b = copyfields(a, b, fields) 2 | 3 | % COPYFIELDS copies a selection of the fields from one structure to another 4 | % 5 | % Use as 6 | % b = copyfields(a, b, fields); 7 | % which copies the specified fields over from structure a to structure b. Fields that 8 | % are specified but not present will be silently ignored. 9 | % 10 | % See also KEEPFIELDS, REMOVEFIELDS, RENAMEFIELDS 11 | 12 | % Copyright (C) 2014, Robert Oostenveld 13 | % 14 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 15 | % for the documentation and details. 16 | % 17 | % FieldTrip is free software: you can redistribute it and/or modify 18 | % it under the terms of the GNU General Public License as published by 19 | % the Free Software Foundation, either version 3 of the License, or 20 | % (at your option) any later version. 21 | % 22 | % FieldTrip is distributed in the hope that it will be useful, 23 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | % GNU General Public License for more details. 26 | % 27 | % You should have received a copy of the GNU General Public License 28 | % along with FieldTrip. If not, see . 29 | % 30 | % $Id$ 31 | 32 | if isempty(a) 33 | % this prevents problems if a is an empty double, i.e. [] 34 | return 35 | end 36 | 37 | if isempty(b) 38 | % this prevents problems if a is an empty double, i.e. [] 39 | b = keepfields(a, fields); 40 | return 41 | end 42 | 43 | if ischar(fields) 44 | fields = {fields}; 45 | elseif ~iscell(fields) 46 | error('fields input argument must be a cell array of strings or a single string'); 47 | end 48 | 49 | fields = intersect(fieldnames(a), fields); 50 | for i=1:numel(fields) 51 | b.(fields{i}) = a.(fields{i}); 52 | end 53 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/fetch_url.m: -------------------------------------------------------------------------------- 1 | function filename = fetch_url(filename) 2 | 3 | % FETCH_URL checks the filename and downloads the file to a local copy in 4 | % case it is specified as an Universal Resource Locator. It returns the 5 | % name of the temporary file on the local filesystem. 6 | % 7 | % Use as 8 | % filename = fetch_url(filename) 9 | % 10 | % In case the filename does not specify an URL, it just returns the original 11 | % filename. 12 | 13 | % Copyright (C) 2012 Robert Oostenveld 14 | % 15 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 16 | % for the documentation and details. 17 | % 18 | % FieldTrip is free software: you can redistribute it and/or modify 19 | % it under the terms of the GNU General Public License as published by 20 | % the Free Software Foundation, either version 3 of the License, or 21 | % (at your option) any later version. 22 | % 23 | % FieldTrip is distributed in the hope that it will be useful, 24 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | % GNU General Public License for more details. 27 | % 28 | % You should have received a copy of the GNU General Public License 29 | % along with FieldTrip. If not, see . 30 | % 31 | % $Id$ 32 | 33 | if filetype_check_uri(filename, 'sftp') 34 | [user, host, filename] = filetype_check_uri(filename); 35 | [p, f, x] = fileparts(filename); 36 | p = tempdir; 37 | try 38 | mkdir(p); 39 | cmd = sprintf('sftp %s@%s:%s %s', user, host, filename, fullfile(p, [f x])); 40 | system(cmd); 41 | filename = fullfile(p, [f x]); 42 | end 43 | % elseif filetype_check_uri(filename, 'http') 44 | % FIXME the http scheme should be supported using default MATLAB 45 | % elseif filetype_check_uri(filename, 'ftp') 46 | % FIXME the http scheme should be supported using default MATLAB 47 | % elseif filetype_check_uri(filename, 'smb') 48 | % FIXME the smb scheme can be supported using smbclient 49 | end 50 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/filetype_check_extension.m: -------------------------------------------------------------------------------- 1 | function [val] = filetype_check_extension(filename, ext) 2 | 3 | % FILETYPE_CHECK_EXTENSION helper function to determine the file type 4 | % by performing a case insensitive string comparison of the extension. 5 | 6 | % Copyright (C) 2003-2012 Robert Oostenveld 7 | % 8 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 9 | % for the documentation and details. 10 | % 11 | % FieldTrip is free software: you can redistribute it and/or modify 12 | % it under the terms of the GNU General Public License as published by 13 | % the Free Software Foundation, either version 3 of the License, or 14 | % (at your option) any later version. 15 | % 16 | % FieldTrip is distributed in the hope that it will be useful, 17 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | % GNU General Public License for more details. 20 | % 21 | % You should have received a copy of the GNU General Public License 22 | % along with FieldTrip. If not, see . 23 | % 24 | % $Id$ 25 | 26 | % these are for remembering the type on subsequent calls with the same input arguments 27 | persistent previous_argin previous_argout 28 | 29 | current_argin = {filename, ext}; 30 | if isequal(current_argin, previous_argin) 31 | % don't do the detection again, but return the previous value from cache 32 | val = previous_argout; 33 | return 34 | end 35 | 36 | if iscell(filename) 37 | % compare the extension of multiple files 38 | val = zeros(size(filename)); 39 | for i=1:length(filename) 40 | val(i) = filetype_check_extension(filename{i}, ext); 41 | end 42 | elseif iscell(ext) 43 | val = zeros(size(ext)); 44 | for i=1:length(ext) 45 | val(i) = filetype_check_extension(filename, ext{i}); 46 | end 47 | else 48 | % compare the extension of a single file 49 | if numel(filename). 24 | % 25 | % $Id$ 26 | 27 | % these are for remembering the type on subsequent calls with the same input arguments 28 | persistent previous_argin previous_argout cache 29 | 30 | if nargin<3 31 | offset = 0; 32 | end 33 | 34 | if isempty(cache) 35 | cache = false; 36 | end 37 | 38 | current_argin = {filename, head, offset}; 39 | if isequal(current_argin, previous_argin) && cache 40 | % don't do the detection again, but return the previous value from cache 41 | val = previous_argout; 42 | return 43 | end 44 | 45 | % from here on it should use the persistent variables as cache to speed up repeated calls 46 | cache = true; 47 | 48 | if iscell(filename) 49 | % compare the header of multiple files 50 | val = zeros(size(filename)); 51 | for i=1:length(filename) 52 | val(i) = filetype_check_header(filename{i}, head, offset); 53 | end 54 | elseif isdir(filename) 55 | % a directory cannot have a header 56 | val = false; 57 | elseif ~exist(filename, 'file') 58 | val = false; 59 | cache = false; % the file does not exist now, but can exist later 60 | else 61 | % read the first few bytes from the file and compare them to the desired header 62 | fid = fopen(filename, 'rb'); 63 | if fid<0 64 | ft_warning(sprintf('could not open %s', filename)); 65 | val = false; 66 | else 67 | fseek(fid, offset, 'cof'); 68 | if iscell(head) 69 | for i=1:length(head) 70 | len(i) = length(head{i}); 71 | end 72 | [str, siz] = fread(fid, max(len), 'uint8'); 73 | fclose(fid); 74 | for i=1:length(head) 75 | val = all(str(1:len(i))==head{i}(:)); 76 | if val 77 | break 78 | end 79 | end 80 | else 81 | [str, siz] = fread(fid, length(head), 'uint8=>char'); 82 | fclose(fid); 83 | if siz~=length(head) 84 | ft_warning(sprintf('could not read the header from %s', filename)); 85 | val = false; 86 | else 87 | val = all(str(:)==head(:)); 88 | end 89 | end 90 | end 91 | end 92 | 93 | % remember the current input and output arguments, so that they can be 94 | % reused on a subsequent call in case the same input argument is given 95 | current_argout = val; 96 | previous_argin = current_argin; 97 | previous_argout = current_argout; 98 | 99 | return % main() 100 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/find_outermost_boundary.m: -------------------------------------------------------------------------------- 1 | function [outermost, inside] = find_outermost_boundary(bnd) 2 | 3 | % FIND_OUTERMOST_BOUNDARY locates outermost compartment of a BEM model 4 | % by looking at the containment of the triangular meshes describing 5 | % the surface boundaries 6 | % 7 | % [outermost] = find_innermost_boundary(bnd) 8 | % 9 | % with the boundaries described by a struct array bnd with 10 | % bnd(i).pnt vertices of boundary i (matrix of size Nx3) 11 | % bnd(i).tri triangles of boundary i (matrix of size Mx3) 12 | 13 | % Copyright (C) 2003, Robert Oostenveld 14 | % 15 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 16 | % for the documentation and details. 17 | % 18 | % FieldTrip is free software: you can redistribute it and/or modify 19 | % it under the terms of the GNU General Public License as published by 20 | % the Free Software Foundation, either version 3 of the License, or 21 | % (at your option) any later version. 22 | % 23 | % FieldTrip is distributed in the hope that it will be useful, 24 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | % GNU General Public License for more details. 27 | % 28 | % You should have received a copy of the GNU General Public License 29 | % along with FieldTrip. If not, see . 30 | % 31 | % $Id$ 32 | 33 | ncmp = length(bnd); 34 | 35 | % try to locate the outermost compartment 36 | for i=1:ncmp 37 | for j=1:ncmp 38 | % determine for a single vertex on each surface if it is inside or outside the other surfaces 39 | curpos1 = bnd(i).pos(1,:); % any point on the boundary is ok 40 | curpos = bnd(j).pos; 41 | curtri = bnd(j).tri; 42 | if i==j 43 | inside(i,j) = 0; 44 | else 45 | inside(i,j) = bounding_mesh(curpos1, curpos, curtri); 46 | end 47 | end 48 | end 49 | % assume that the sources are in the innermost compartment 50 | tmp = sum(inside, 2); 51 | [i, outermost] = min(tmp); 52 | 53 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/fixname.m: -------------------------------------------------------------------------------- 1 | function str = fixname(str) 2 | 3 | % FIXNAME changes all inappropriate characters in a sting into '_' 4 | % such that it can be used as a filename or as a structure field name. If 5 | % the string begins with a numeric digit, an 'x' is prepended. 6 | % 7 | % Use as 8 | % str = fixname(str) 9 | % 10 | % MATLAB 2014a introduces the matlab.lang.makeValidName and 11 | % matlab.lang.makeUniqueStrings functions for constructing unique MATLAB identifiers, 12 | % but this particular implementation also works with older MATLAB versions. 13 | % 14 | % See also DEBLANK 15 | 16 | % Copyright (C) 2012-2016, Robert Oostenveld 17 | % 18 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 19 | % for the documentation and details. 20 | % 21 | % FieldTrip is free software: you can redistribute it and/or modify 22 | % it under the terms of the GNU General Public License as published by 23 | % the Free Software Foundation, either version 3 of the License, or 24 | % (at your option) any later version. 25 | % 26 | % FieldTrip is distributed in the hope that it will be useful, 27 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | % GNU General Public License for more details. 30 | % 31 | % You should have received a copy of the GNU General Public License 32 | % along with FieldTrip. If not, see . 33 | % 34 | % $Id$ 35 | 36 | str = lower(str); 37 | str(regexp(str,'\W')) = '_'; 38 | 39 | while(str(1) == '_'), str = str(2:end); end; % remove all underscore at the begin of the string 40 | while(str(end) == '_'), str = str(1:end-1); end; % remove all underscore at the end of the string 41 | 42 | if int8(str(1))<58 && int8(str(1))>47 43 | % the string begins with a digit, prepend an 'x' 44 | str = ['x' str]; 45 | end 46 | 47 | % truncate the string if it's too long: MATLAB maximizes the string length to 63 characters (and throws a warning when truncating) 48 | if numel(str)>63 49 | str = str(1:63); 50 | ft_warning(sprintf('%s exceeds MATLAB''s maximum name length of 63 characters and has been truncated to %s', str, str(1:63))); 51 | end 52 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/fixpos.m: -------------------------------------------------------------------------------- 1 | function mesh = fixpos(mesh, recurse) 2 | 3 | % FIXPOS helper function to ensure that meshes are described properly 4 | 5 | if nargin==1 6 | recurse = 1; 7 | end 8 | 9 | if isa(mesh, 'delaunayTriangulation') 10 | % convert to structure, otherwise the code below won't work properly 11 | ws = warning('off', 'MATLAB:structOnObject'); 12 | mesh = struct(mesh); 13 | warning(ws); 14 | end 15 | 16 | if ~isa(mesh, 'struct') 17 | return; 18 | end 19 | 20 | if numel(mesh)>1 21 | % loop over all individual elements 22 | clear tmp 23 | for i=1:numel(mesh) 24 | % this is to prevent an "Subscripted assignment between dissimilar structures" error 25 | tmp(i) = fixpos(mesh(i)); 26 | end 27 | mesh = tmp; 28 | clear tmp 29 | return 30 | end 31 | 32 | % convert from MATLAB delaunayTriangulation output to FieldTrip convention 33 | if isfield(mesh, 'Points') && isfield(mesh, 'ConnectivityList') 34 | mesh.pos = mesh.Points; 35 | switch size(mesh.ConnectivityList,2) 36 | case 2 37 | mesh.edge = mesh.ConnectivityList; 38 | case 3 39 | mesh.tri = mesh.ConnectivityList; 40 | case 4 41 | mesh.tet = mesh.ConnectivityList; 42 | case 8 43 | mesh.hex = mesh.ConnectivityList; 44 | otherwise 45 | error('unsupported ConnectivityList') 46 | end % switch 47 | mesh = rmfield(mesh, {'Points', 'ConnectivityList', 'Constraints'}); 48 | end 49 | 50 | % convert from BrainStorm/MNE to FieldTrip convention 51 | if isfield(mesh, 'vertices') && isfield(mesh, 'faces') 52 | mesh.pos = mesh.vertices; 53 | mesh.tri = mesh.faces; 54 | mesh = rmfield(mesh, {'faces', 'vertices'}); 55 | elseif isfield(mesh, 'Vertices') && isfield(mesh, 'Faces') 56 | mesh.pos = mesh.Vertices; 57 | mesh.tri = mesh.Faces; 58 | mesh = rmfield(mesh, {'Faces', 'Vertices'}); 59 | end 60 | 61 | % replace pnt by pos 62 | if isfield(mesh, 'pnt') 63 | mesh.pos = mesh.pnt; 64 | mesh = rmfield(mesh, 'pnt'); 65 | end 66 | 67 | if recurse<3 68 | % recurse into substructures, not too deep 69 | fn = fieldnames(mesh); 70 | fn = setdiff(fn, {'cfg'}); % don't recurse into the cfg structure 71 | for i=1:length(fn) 72 | if isstruct(mesh.(fn{i})) 73 | mesh.(fn{i}) = fixpos(mesh.(fn{i}), recurse+1); 74 | end 75 | end 76 | end 77 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/ft_estimate_units.m: -------------------------------------------------------------------------------- 1 | function unit = ft_estimate_units(size) 2 | 3 | % FT_ESTIMATE_UNITS tries to determine the units of a geometrical object by 4 | % looking at its size and by relating this to the approximate size of the 5 | % human head according to the following table: 6 | % from 0.050 to 0.500 -> meter 7 | % from 0.500 to 5.000 -> decimeter 8 | % from 5.000 to 50.000 -> centimeter 9 | % from 50.000 to 500.000 -> millimeter 10 | % 11 | % Use as 12 | % unit = ft_estimate_units(size) 13 | % 14 | % This function will return one of the following strings 15 | % 'm' 16 | % 'dm' 17 | % 'cm' 18 | % 'mm' 19 | % 20 | % See also FT_CONVERT_UNITS 21 | 22 | % Copyright (C) 2009-2013, Robert Oostenveld 23 | % 24 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 25 | % for the documentation and details. 26 | % 27 | % FieldTrip is free software: you can redistribute it and/or modify 28 | % it under the terms of the GNU General Public License as published by 29 | % the Free Software Foundation, either version 3 of the License, or 30 | % (at your option) any later version. 31 | % 32 | % FieldTrip is distributed in the hope that it will be useful, 33 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 34 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 35 | % GNU General Public License for more details. 36 | % 37 | % You should have received a copy of the GNU General Public License 38 | % along with FieldTrip. If not, see . 39 | % 40 | % $Id$ 41 | 42 | % do some magic based on the size 43 | unit = {'m', 'dm', 'cm', 'mm'}; 44 | est = log10(size)+1.8; 45 | indx = round(est); 46 | 47 | if indx>length(unit) 48 | indx = length(unit); 49 | warning('assuming that the units are "%s"', unit{indx}); 50 | elseif indx<1 51 | indx = 1; 52 | warning('assuming that the units are "%s"', unit{indx}); 53 | elseif abs((est-floor(est)) - 0.5)<0.1 54 | % the size estimate falls within the expected range, but is not very decisive 55 | % for example round(1.49) results in meter, but round(1.51) results in decimeter 56 | warning('the estimated units are not very decisive, assuming that the units are "%s"', unit{indx}); 57 | end 58 | 59 | unit = unit{indx}; 60 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/ft_getopt.m: -------------------------------------------------------------------------------- 1 | function val = ft_getopt(opt, key, default, emptymeaningful) 2 | 3 | % FT_GETOPT gets the value of a specified option from a configuration structure 4 | % or from a cell-array with key-value pairs. 5 | % 6 | % Use as 7 | % val = ft_getopt(s, key, default, emptymeaningful) 8 | % where the input values are 9 | % s = structure or cell-array 10 | % key = string 11 | % default = any valid MATLAB data type 12 | % emptymeaningful = boolean value (optional, default = 0) 13 | % 14 | % If the key is present as field in the structure, or as key-value 15 | % pair in the cell-array, the corresponding value will be returned. 16 | % 17 | % If the key is not present, ft_getopt will return an empty array. 18 | % 19 | % If the key is present but has an empty value, then the emptymeaningful 20 | % flag specifies whether the empty value or the default value should 21 | % be returned. If emptymeaningful==true, then an empty array will be 22 | % returned. If emptymeaningful==false, then the specified default will 23 | % be returned. 24 | % 25 | % See also FT_SETOPT, FT_CHECKOPT 26 | 27 | % Copyright (C) 2011-2012, Robert Oostenveld 28 | % 29 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 30 | % for the documentation and details. 31 | % 32 | % FieldTrip is free software: you can redistribute it and/or modify 33 | % it under the terms of the GNU General Public License as published by 34 | % the Free Software Foundation, either version 3 of the License, or 35 | % (at your option) any later version. 36 | % 37 | % FieldTrip is distributed in the hope that it will be useful, 38 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 39 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 40 | % GNU General Public License for more details. 41 | % 42 | % You should have received a copy of the GNU General Public License 43 | % along with FieldTrip. If not, see . 44 | % 45 | % $Id$ 46 | 47 | if nargin<3 48 | default = []; 49 | end 50 | 51 | if nargin < 4 52 | emptymeaningful = 0; 53 | end 54 | 55 | if isa(opt, 'struct') || isa(opt, 'config') 56 | % get the key-value from the structure 57 | fn = fieldnames(opt); 58 | if ~any(strcmp(key, fn)) 59 | val = default; 60 | else 61 | val = opt.(key); 62 | end 63 | 64 | elseif isa(opt, 'cell') 65 | % get the key-value from the cell-array 66 | if mod(length(opt),2) 67 | error('optional input arguments should come in key-value pairs, i.e. there should be an even number'); 68 | end 69 | 70 | % the 1st, 3rd, etc. contain the keys, the 2nd, 4th, etc. contain the values 71 | keys = opt(1:2:end); 72 | vals = opt(2:2:end); 73 | 74 | % the following may be faster than cellfun(@ischar, keys) 75 | valid = false(size(keys)); 76 | for i=1:numel(keys) 77 | valid(i) = ischar(keys{i}); 78 | end 79 | 80 | if ~all(valid) 81 | error('optional input arguments should come in key-value pairs, the optional input argument %d is invalid (should be a string)', i); 82 | end 83 | 84 | hit = find(strcmpi(key, keys)); 85 | if isempty(hit) 86 | % the requested key was not found 87 | val = default; 88 | elseif length(hit)==1 89 | % the requested key was found 90 | val = vals{hit}; 91 | else 92 | error('multiple input arguments with the same name'); 93 | end 94 | 95 | elseif isempty(opt) 96 | % no options are specified, return default 97 | val = default; 98 | end % isstruct or iscell or isempty 99 | 100 | if isempty(val) && ~isempty(default) && ~emptymeaningful 101 | % use the default value instead of the empty input that was specified: 102 | % this applies for example if you do functionname('key', []), where 103 | % the empty is meant to indicate that the user does not know or care 104 | % what the value is 105 | val = default; 106 | end 107 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/ft_getopt.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/cifti-matlab-master/private/ft_getopt.mexa64 -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/ft_getopt.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/cifti-matlab-master/private/ft_getopt.mexglx -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/ft_getopt.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/cifti-matlab-master/private/ft_getopt.mexmaci -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/ft_getopt.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/cifti-matlab-master/private/ft_getopt.mexmaci64 -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/ft_getopt.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/cifti-matlab-master/private/ft_getopt.mexw32 -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/ft_getopt.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/cifti-matlab-master/private/ft_getopt.mexw64 -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/ft_read_vol.m: -------------------------------------------------------------------------------- 1 | function [headmodel] = ft_read_vol(filename, varargin) 2 | 3 | % FT_READ_VOL reads a volume conduction model from various manufacturer 4 | % specific files. Currently supported are ASA, CTF, Neuromag, MBFYS 5 | % and Matlab. 6 | % 7 | % Use as 8 | % headmodel = ft_read_vol(filename, ...) 9 | % 10 | % Additional options should be specified in key-value pairs and can be 11 | % 'fileformat' string 12 | % 13 | % The volume conduction model is represented as a structure with fields 14 | % that depend on the type of model. 15 | % 16 | % See also FT_TRANSFORM_VOL, FT_PREPARE_VOL_SENS, FT_COMPUTE_LEADFIELD 17 | 18 | % Copyright (C) 2008-2013 Robert Oostenveld 19 | % 20 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 21 | % for the documentation and details. 22 | % 23 | % FieldTrip is free software: you can redistribute it and/or modify 24 | % it under the terms of the GNU General Public License as published by 25 | % the Free Software Foundation, either version 3 of the License, or 26 | % (at your option) any later version. 27 | % 28 | % FieldTrip is distributed in the hope that it will be useful, 29 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 30 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 31 | % GNU General Public License for more details. 32 | % 33 | % You should have received a copy of the GNU General Public License 34 | % along with FieldTrip. If not, see . 35 | % 36 | % $Id$ 37 | 38 | % optionally get the data from the URL and make a temporary local copy 39 | filename = fetch_url(filename); 40 | 41 | % test whether the file exists 42 | if ~exist(filename) 43 | error(sprintf('file ''%s'' does not exist', filename)); 44 | end 45 | 46 | % get the options 47 | fileformat = ft_getopt(varargin, 'fileformat', ft_filetype(filename)); 48 | 49 | switch fileformat 50 | case 'matlab' 51 | % FIXME in the future the file should contain the variable 'headmodel' instead of vol 52 | headmodel = loadvar(filename, 'vol'); 53 | 54 | case 'ctf_hdm' 55 | headmodel = read_ctf_hdm(filename); 56 | 57 | case 'asa_vol' 58 | headmodel = read_asa_vol(filename); 59 | headmodel.type = 'asa'; 60 | 61 | case 'mbfys_ama' 62 | ama = loadama(filename); 63 | headmodel = ama2vol(ama); 64 | 65 | otherwise 66 | error('unknown fileformat for volume conductor model'); 67 | end 68 | 69 | % this will ensure that the structure is up to date, e.g. that the type is correct and that it has units 70 | headmodel = ft_datatype_headmodel(headmodel); 71 | 72 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/ft_struct2double.m: -------------------------------------------------------------------------------- 1 | function [x] = ft_struct2double(x, maxdepth) 2 | 3 | % FT_STRUCT2DOUBLE converts all single precision numeric data in a structure 4 | % into double precision. It will also convert plain matrices and 5 | % cell-arrays. 6 | % 7 | % Use as 8 | % x = ft_struct2double(x) 9 | % 10 | % Starting from MATLAB 7.0, you can use single precision data in your 11 | % computations, i.e. you do not have to convert back to double precision. 12 | % 13 | % MATLAB version 6.5 and older only support single precision for storing 14 | % data in memory or on disk, but do not allow computations on single 15 | % precision data. Therefore you should converted your data from single to 16 | % double precision after reading from file. 17 | % 18 | % See also FT_STRUCT2SINGLE 19 | 20 | % Copyright (C) 2005-2014, Robert Oostenveld 21 | % 22 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 23 | % for the documentation and details. 24 | % 25 | % FieldTrip is free software: you can redistribute it and/or modify 26 | % it under the terms of the GNU General Public License as published by 27 | % the Free Software Foundation, either version 3 of the License, or 28 | % (at your option) any later version. 29 | % 30 | % FieldTrip is distributed in the hope that it will be useful, 31 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 32 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 | % GNU General Public License for more details. 34 | % 35 | % You should have received a copy of the GNU General Public License 36 | % along with FieldTrip. If not, see . 37 | % 38 | % $Id$ 39 | 40 | if nargin<2 41 | maxdepth = inf; 42 | end 43 | 44 | % convert the data, work recursively through the complete structure 45 | x = convert(x, 0, maxdepth); 46 | 47 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 48 | % this subfunction does the actual work 49 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 50 | function [a] = convert(a, depth, maxdepth) 51 | 52 | if depth>maxdepth 53 | error('recursive depth exceeded'); 54 | end 55 | 56 | switch class(a) 57 | case 'struct' 58 | % process all fields of the structure recursively 59 | fna = fieldnames(a); 60 | % process all elements of the array 61 | for j=1:length(a(:)) 62 | % warning, this is a recursive call to traverse nested structures 63 | for i=1:length(fna) 64 | fn = fna{i}; 65 | ra = getfield(a(j), fn); 66 | ra = convert(ra, depth+1, maxdepth); 67 | a(j) = setfield(a(j), fn, ra); 68 | end 69 | end 70 | 71 | case 'cell' 72 | % process all elements of the cell-array recursively 73 | % warning, this is a recursive call to traverse nested structures 74 | for i=1:length(a(:)) 75 | a{i} = convert(a{i}, depth+1, maxdepth); 76 | end 77 | 78 | case {'single' 'int64' 'uint64' 'int32' 'uint32' 'int16' 'uint16' 'int8' 'uint8'} 79 | % convert the values to double precision 80 | a = double(a); 81 | 82 | case 'double' 83 | % keep as it is 84 | 85 | otherwise 86 | % do nothing 87 | end 88 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/getdimsiz.m: -------------------------------------------------------------------------------- 1 | function dimsiz = getdimsiz(data, field) 2 | 3 | % GETDIMSIZ 4 | % 5 | % Use as 6 | % dimsiz = getdimsiz(data, field) 7 | % 8 | % If the length of the vector that is returned is smaller than the 9 | % number of dimensions that you would expect from GETDIMORD, you 10 | % should assume that it has trailing singleton dimensions. 11 | % 12 | % Example use 13 | % dimord = getdimord(datastructure, fieldname); 14 | % dimtok = tokenize(dimord, '_'); 15 | % dimsiz = getdimsiz(datastructure, fieldname); 16 | % dimsiz(end+1:length(dimtok)) = 1; % there can be additional trailing singleton dimensions 17 | % 18 | % See also GETDIMORD, GETDATFIELD 19 | 20 | if ~isfield(data, field) && isfield(data, 'avg') && isfield(data.avg, field) 21 | field = ['avg.' field]; 22 | elseif ~isfield(data, field) && isfield(data, 'trial') && isfield(data.trial, field) 23 | field = ['trial.' field]; 24 | elseif ~isfield(data, field) 25 | error('field "%s" not present in data', field); 26 | end 27 | 28 | if strncmp(field, 'avg.', 4) 29 | prefix = []; 30 | field = field(5:end); % strip the avg 31 | data.(field) = data.avg.(field); % move the avg into the main structure 32 | data = rmfield(data, 'avg'); 33 | elseif strncmp(field, 'trial.', 6) 34 | prefix = numel(data.trial); 35 | field = field(7:end); % strip the trial 36 | data.(field) = data.trial(1).(field); % move the first trial into the main structure 37 | data = rmfield(data, 'trial'); 38 | else 39 | prefix = []; 40 | end 41 | 42 | dimsiz = cellmatsize(data.(field)); 43 | 44 | % add nrpt in case of source.trial 45 | dimsiz = [prefix dimsiz]; 46 | 47 | end % main function 48 | 49 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 50 | % SUBFUNCTION to determine the size of data representations like {pos}_ori_time 51 | % FIXME this will fail for {xxx_yyy}_zzz 52 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 53 | function siz = cellmatsize(x) 54 | if iscell(x) 55 | if isempty(x) 56 | siz = 0; 57 | return % nothing else to do 58 | elseif isvector(x) 59 | cellsize = numel(x); % the number of elements in the cell-array 60 | else 61 | cellsize = size(x); 62 | x = x(:); % convert to vector for further size detection 63 | end 64 | [dum, indx] = max(cellfun(@numel, x)); 65 | matsize = size(x{indx}); % the size of the content of the cell-array 66 | siz = [cellsize matsize]; % concatenate the two 67 | else 68 | siz = size(x); 69 | end 70 | end % function cellmatsize 71 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/hasyokogawa.m: -------------------------------------------------------------------------------- 1 | function [version] = hasyokogawa(desired) 2 | 3 | % HASYOKOGAWA tests whether the data input toolbox for MEG systems by 4 | % Yokogawa (www.yokogawa.com, designed by KIT/EagleTechnology) is 5 | % installed. Only the newest version of the toolbox is accepted. 6 | % 7 | % Use as 8 | % string = hasyokogawa; 9 | % which returns a string describing the toolbox version, e.g. "12bitBeta3", 10 | % "16bitBeta3", or "16bitBeta6" for preliminary versions, or '1.4' for the 11 | % official Yokogawa MEG Reader Toolbox. An empty string is returned if the toolbox 12 | % is not installed. The string "unknown" is returned if it is installed but 13 | % the version is unknown. 14 | % 15 | % Alternatively you can use it as 16 | % [boolean] = hasyokogawa(desired); 17 | % where desired is a string with the desired version. 18 | % 19 | % See also READ_YOKOGAWA_HEADER, READ_YOKOGAWA_DATA, READ_YOKOGAWA_EVENT, 20 | % YOKOGAWA2GRAD 21 | 22 | % Copyright (C) 2010, Tilmann Sander-Thoemmes 23 | % 24 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 25 | % for the documentation and details. 26 | % 27 | % FieldTrip is free software: you can redistribute it and/or modify 28 | % it under the terms of the GNU General Public License as published by 29 | % the Free Software Foundation, either version 3 of the License, or 30 | % (at your option) any later version. 31 | % 32 | % FieldTrip is distributed in the hope that it will be useful, 33 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 34 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 35 | % GNU General Public License for more details. 36 | % 37 | % You should have received a copy of the GNU General Public License 38 | % along with FieldTrip. If not, see . 39 | % 40 | % $Id$ 41 | 42 | ws = warning('off', 'MATLAB:pfileOlderThanMfile'); 43 | 44 | % there are a few versions of the old preliminary implementation, such as 45 | % 12bitBeta3, 16bitBeta3 and 16bitBeta6. In 2011 a completely new 46 | % implementation was officially released, which contains functions with 47 | % other names. At the time of writing this, the new implementation is 48 | % version 1.4. 49 | 50 | if exist('getYkgwVersion') 51 | res = getYkgwVersion(); 52 | version = res.version; 53 | 54 | elseif exist('GetMeg160ADbitInfoM') || exist('GetMeg160ChannelInfoM') || exist('GetMeg160ContinuousRawDataM') 55 | % start with unknown, try to refine the version 56 | version = 'unknown'; 57 | 58 | try 59 | % Call some functions with input argument "Inf": If 60 | % the functions are present they return their revision number. 61 | % Call first GetMeg160ADbitInfoM as this is not present in 62 | % the 12bit library, in case of error the "catch" part will take over. 63 | % The code below is intentionally very literal for easy of reading. 64 | res = textscan(evalc('GetMeg160ADbitInfoM(Inf);'),'%s %s %c %s %s %d'); 65 | rev_ADbitInfoM = res{6}; 66 | res = textscan(evalc('GetMeg160ChannelInfoM(Inf);'),'%s %s %c %s %s %d'); 67 | rev_ChannelInfoM = res{6}; 68 | res = textscan(evalc('GetMeg160AmpGainM(Inf);'),'%s %s %c %s %s %d'); 69 | rev_AmpGainM = res{6}; 70 | res = textscan(evalc('GetMeg160MatchingInfoM(Inf);'),'%s %s %c %s %s %d'); 71 | rev_MatchingInfoM = res{6}; 72 | if [0 2 1 5] == [rev_ADbitInfoM rev_ChannelInfoM rev_AmpGainM rev_MatchingInfoM] 73 | version='16bitBeta3'; 74 | elseif [0 2 2 5] == [rev_ADbitInfoM rev_ChannelInfoM rev_AmpGainM rev_MatchingInfoM] 75 | version='16bitBeta6'; 76 | else 77 | warning('The version of the installed Yokogawa toolbox cannot be determined.'); 78 | end 79 | catch 80 | m = lasterror; 81 | m.identifier; 82 | if strcmp(m.identifier, 'MATLAB:UndefinedFunction') || strcmp(m.identifier, 'MATLAB:FileIO:InvalidFid') 83 | if (exist('GetMeg160ChannelInfoM') && exist('GetMeg160ContinuousRawDataM')); 84 | version = '12bitBeta3'; 85 | end 86 | end 87 | end 88 | 89 | else 90 | % return empty if none of them is present 91 | version = []; 92 | end 93 | 94 | if nargin>0 95 | % return a true/false value 96 | if isempty(version) 97 | version = false; 98 | else 99 | version = strcmpi(version, desired); 100 | end 101 | end 102 | 103 | % revert to the original warning state 104 | warning(ws); 105 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/individual2sn.m: -------------------------------------------------------------------------------- 1 | function [warped]= individual2sn(P, input) 2 | 3 | % INDIVIDUAL2SN warps the input coordinates (defined as Nx3 matrix) from 4 | % individual headspace coordinates into normalised MNI coordinates, using the 5 | % (inverse of the) warp parameters defined in the structure spmparams. 6 | % 7 | % this is code inspired by nutmeg and spm: nut_mri2mni, nut_spm_sn2def and 8 | % nut_spm_invdef which were themselves modified from code originally written 9 | % by John Ashburner: 10 | % http://www.sph.umich.edu/~nichols/JohnsGems2.html 11 | % 12 | % Use as 13 | % [warped] = individual2sn(P, input) 14 | % 15 | % Input parameters: 16 | % P = structure that contains the contents of an spm generated _sn.mat 17 | % file 18 | % input = Nx3 array containing the input positions 19 | 20 | % Copyright (C) 2013, Jan-Mathijs Schoffelen 21 | % 22 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 23 | % for the documentation and details. 24 | % 25 | % FieldTrip is free software: you can redistribute it and/or modify 26 | % it under the terms of the GNU General Public License as published by 27 | % the Free Software Foundation, either version 3 of the License, or 28 | % (at your option) any later version. 29 | % 30 | % FieldTrip is distributed in the hope that it will be useful, 31 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 32 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 | % GNU General Public License for more details. 34 | % 35 | % You should have received a copy of the GNU General Public License 36 | % along with FieldTrip. If not, see . 37 | % 38 | % $Id$ 39 | 40 | ft_hastoolbox('spm8up', 1); 41 | 42 | % The following is a three-step procedure 43 | 44 | % 1: create the spatial deformation field from the sn parameters 45 | [Def, M] = get_sn2def(P); 46 | 47 | % 2a: invert the spatial deformation field 48 | [p,f,e] = fileparts(which('spm_invdef')); 49 | templatedirname = fullfile(p,'templates'); 50 | d = dir([templatedirname,'/T1*']); 51 | VT = spm_vol(fullfile(templatedirname,d(1).name)); 52 | [iy1,iy2,iy3] = spm_invdef(Def{1},Def{2},Def{3},VT.dim(1:3),inv(VT.mat),M); 53 | 54 | % 2b: write the deformation fields in x/y/z direction to temporary files 55 | V1.fname = [tempname '.img']; 56 | V1.dim(1:3) = VT.dim(1:3); 57 | V1.pinfo = [1 0 0]'; 58 | V1.mat = VT.mat; 59 | V1.dt = [64 0]; 60 | V1.descrip = 'Inverse deformation field'; 61 | spm_write_vol(V1,iy1); 62 | 63 | V2.fname = [tempname '.img']; 64 | V2.dim(1:3) = VT.dim(1:3); 65 | V2.pinfo = [1 0 0]'; 66 | V2.mat = VT.mat; 67 | V2.dt = [64 0]; 68 | V2.descrip = 'Inverse deformation field'; 69 | spm_write_vol(V2,iy2); 70 | 71 | V3.fname = [tempname '.img']; 72 | V3.dim(1:3) = VT.dim(1:3); 73 | V3.pinfo = [1 0 0]'; 74 | V3.mat = VT.mat; 75 | V3.dt = [64 0]; 76 | V3.descrip = 'Inverse deformation field'; 77 | spm_write_vol(V3,iy3); 78 | 79 | % 3: extract the coordinates 80 | warped = ft_warp_apply(inv(V1.mat), input); % Express as voxel indices 81 | warped = cat(2, spm_sample_vol(V1,warped(:,1),warped(:,2),warped(:,3),1), ... 82 | spm_sample_vol(V2,warped(:,1),warped(:,2),warped(:,3),1), ... 83 | spm_sample_vol(V3,warped(:,1),warped(:,2),warped(:,3),1)); 84 | 85 | %_______________________________________________________________________ 86 | function [Def,mat] = get_sn2def(sn) 87 | % Convert a SPM _sn.mat file into a deformation field, and return it. 88 | % This is code that was taken from SPM8. 89 | 90 | dim = sn.VG(1).dim; 91 | x = 1:dim(1); 92 | y = 1:dim(2); 93 | z = 1:dim(3); 94 | mat = sn.VG(1).mat; 95 | 96 | [X,Y] = ndgrid(x,y); 97 | 98 | st = size(sn.Tr); 99 | 100 | if (prod(st) == 0), 101 | affine_only = true; 102 | basX = 0; 103 | basY = 0; 104 | basZ = 0; 105 | else 106 | affine_only = false; 107 | basX = spm_dctmtx(sn.VG(1).dim(1),st(1),x-1); 108 | basY = spm_dctmtx(sn.VG(1).dim(2),st(2),y-1); 109 | basZ = spm_dctmtx(sn.VG(1).dim(3),st(3),z-1); 110 | end, 111 | 112 | Def = single(0); 113 | Def(numel(x),numel(y),numel(z)) = 0; 114 | Def = {Def; Def; Def}; 115 | 116 | for j=1:length(z) 117 | if (~affine_only) 118 | tx = reshape( reshape(sn.Tr(:,:,:,1),st(1)*st(2),st(3)) *basZ(j,:)', st(1), st(2) ); 119 | ty = reshape( reshape(sn.Tr(:,:,:,2),st(1)*st(2),st(3)) *basZ(j,:)', st(1), st(2) ); 120 | tz = reshape( reshape(sn.Tr(:,:,:,3),st(1)*st(2),st(3)) *basZ(j,:)', st(1), st(2) ); 121 | 122 | X1 = X + basX*tx*basY'; 123 | Y1 = Y + basX*ty*basY'; 124 | Z1 = z(j) + basX*tz*basY'; 125 | end 126 | 127 | Mult = sn.VF.mat*sn.Affine; 128 | if (~affine_only) 129 | X2= Mult(1,1)*X1 + Mult(1,2)*Y1 + Mult(1,3)*Z1 + Mult(1,4); 130 | Y2= Mult(2,1)*X1 + Mult(2,2)*Y1 + Mult(2,3)*Z1 + Mult(2,4); 131 | Z2= Mult(3,1)*X1 + Mult(3,2)*Y1 + Mult(3,3)*Z1 + Mult(3,4); 132 | else 133 | X2= Mult(1,1)*X + Mult(1,2)*Y + (Mult(1,3)*z(j) + Mult(1,4)); 134 | Y2= Mult(2,1)*X + Mult(2,2)*Y + (Mult(2,3)*z(j) + Mult(2,4)); 135 | Z2= Mult(3,1)*X + Mult(3,2)*Y + (Mult(3,3)*z(j) + Mult(3,4)); 136 | end 137 | 138 | Def{1}(:,:,j) = single(X2); 139 | Def{2}(:,:,j) = single(Y2); 140 | Def{3}(:,:,j) = single(Z2); 141 | end; 142 | %_______________________________________________________________________ 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/inflate_file.m: -------------------------------------------------------------------------------- 1 | function outputfile = inflate_file(inputfile) 2 | 3 | % INFLATE_FILE helper function to uncompress a compressed file of arbitrary 4 | % compression type. Returns the full path to the extracted file or 5 | % directory, which will be located in a temporary location. 6 | 7 | % Copyright (C) 2012 Eelke Spaak 8 | % 9 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 10 | % for the documentation and details. 11 | % 12 | % FieldTrip is free software: you can redistribute it and/or modify 13 | % it under the terms of the GNU General Public License as published by 14 | % the Free Software Foundation, either version 3 of the License, or 15 | % (at your option) any later version. 16 | % 17 | % FieldTrip is distributed in the hope that it will be useful, 18 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | % GNU General Public License for more details. 21 | % 22 | % You should have received a copy of the GNU General Public License 23 | % along with FieldTrip. If not, see . 24 | % 25 | % $Id$ 26 | 27 | % use a cache to prevent extracting the same file multiple times 28 | persistent extractcache; 29 | inputfilemd5 = fixname(CalcMD5(inputfile)); 30 | if isfield(extractcache, inputfilemd5) 31 | outputfile = extractcache.(inputfilemd5); 32 | if exist(outputfile, 'file') % checks for files or folders 33 | fprintf('compressed dataset has already been extracted to %s\n', outputfile); 34 | return; 35 | else 36 | % apparently the file is gone 37 | extractcache = rmfield(extractcache, inputfilemd5); 38 | end 39 | end 40 | 41 | % determine compression type 42 | if filetype_check_extension(inputfile, 'zip') 43 | type = 'zip'; 44 | elseif filetype_check_extension(inputfile, 'tar')... 45 | || filetype_check_extension(inputfile, '.tar.gz')... 46 | || filetype_check_extension(inputfile, 'tgz') 47 | type = 'tar'; 48 | elseif filetype_check_extension(inputfile, 'gz') 49 | type = 'gzip'; 50 | else 51 | error('unsupported compression type, only zip/tar(gz)/gz are supported'); 52 | end 53 | 54 | % determine temporary output folder 55 | outputdir = [tempdir() inputfilemd5]; 56 | 57 | % give some feedback 58 | fprintf('extracting compressed dataset to %s...\n', outputdir); 59 | 60 | % do appropriate inflation 61 | switch (type) 62 | case 'zip' 63 | unzip(inputfile, outputdir); 64 | case 'tar' 65 | untar(inputfile, outputdir); 66 | case 'gzip' 67 | gunzip(inputfile, outputdir); 68 | end 69 | 70 | % if we extracted only a single file (or directory), return path to that file, if it was a 71 | % set of files, return path to the biggeset file 72 | outfiles = dir(outputdir); 73 | if numel(outfiles) == 3 % first two will always be . and .. 74 | outputfile = [outputdir '/' outfiles(3).name]; 75 | else 76 | siz = [outfiles.bytes]; 77 | maxind = find(siz == max(siz),1); % use find() because we want at most 1 78 | outputfile = [outputdir '/' outfiles(maxind).name]; 79 | end 80 | 81 | fprintf('extracted dataset is located at %s\n', outputfile); 82 | extractcache.(inputfilemd5) = outputfile; 83 | 84 | end 85 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/istrue.m: -------------------------------------------------------------------------------- 1 | function y = istrue(x) 2 | 3 | % ISTRUE ensures that a true/false input argument like "yes", "true" 4 | % or "on" is converted into a boolean 5 | 6 | % Copyright (C) 2009-2012, Robert Oostenveld 7 | % 8 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 9 | % for the documentation and details. 10 | % 11 | % FieldTrip is free software: you can redistribute it and/or modify 12 | % it under the terms of the GNU General Public License as published by 13 | % the Free Software Foundation, either version 3 of the License, or 14 | % (at your option) any later version. 15 | % 16 | % FieldTrip is distributed in the hope that it will be useful, 17 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | % GNU General Public License for more details. 20 | % 21 | % You should have received a copy of the GNU General Public License 22 | % along with FieldTrip. If not, see . 23 | % 24 | % $Id$ 25 | 26 | true_list = {'yes' 'true' 'on' 'y' }; 27 | false_list = {'no' 'false' 'off' 'n' 'none'}; 28 | 29 | if ischar(x) 30 | % convert string to boolean value 31 | if any(strcmpi(x, true_list)) 32 | y = true; 33 | elseif any(strcmpi(x, false_list)) 34 | y = false; 35 | else 36 | error('cannot determine whether "%s" should be interpreted as true or false', x); 37 | end 38 | else 39 | % convert numerical value to boolean 40 | y = logical(x); 41 | end 42 | 43 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/keepfields.m: -------------------------------------------------------------------------------- 1 | function [s] = keepfields(s, fields) 2 | 3 | % KEEPFIELDS makes a selection of the fields in a structure 4 | % 5 | % Use as 6 | % s = keepfields(s, fields); 7 | % 8 | % See also REMOVEFIELDS, COPYFIELDS 9 | 10 | % Copyright (C) 2014, Robert Oostenveld 11 | % 12 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 13 | % for the documentation and details. 14 | % 15 | % FieldTrip is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % FieldTrip is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with FieldTrip. If not, see . 27 | % 28 | % $Id$ 29 | 30 | if isempty(s) 31 | % this prevents problems if s is an empty double, i.e. [] 32 | return 33 | end 34 | 35 | if ischar(fields) 36 | fields = {fields}; 37 | elseif ~iscell(fields) 38 | error('fields input argument must be a cell array of strings or a single string'); 39 | end 40 | 41 | fields = setdiff(fieldnames(s), fields); 42 | for i=1:numel(fields) 43 | s = rmfield(s, fields{i}); 44 | end 45 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/ndgrid.m: -------------------------------------------------------------------------------- 1 | function [varargout] = ndgrid(varargin) 2 | 3 | % NDGRID Generation of arrays for N-D functions and interpolation. 4 | % [X1,X2,X3,...] = NDGRID(x1,x2,x3,...) transforms the domain 5 | % specified by vectors x1,x2,x3, etc. into arrays X1,X2,X3, etc. that 6 | % can be used for the evaluation of functions of N variables and N-D 7 | % interpolation. The i-th dimension of the output array Xi are copies 8 | % of elements of the vector xi. 9 | % 10 | % [X1,X2,...] = NDGRID(x) is the same as [X1,X2,...] = NDGRID(x,x,...). 11 | % 12 | % For example, to evaluate the function x2*exp(-x1^2-x2^2-x^3) over the 13 | % range -2 < x1 < 2, -2 < x2 < 2, -2 < x3 < 2, 14 | % 15 | % [x1,x2,x3] = ndgrid(-2:.2:2, -2:.25:2, -2:.16:2); 16 | % z = x2 .* exp(-x1.^2 - x2.^2 - x3.^2); 17 | % slice(x2,x1,x3,z,[-1.2 .8 2],2,[-2 -.2]) 18 | % 19 | % NDGRID is like MESHGRID except that the order of the first two input 20 | % arguments are switched (i.e., [X1,X2,X3] = NDGRID(x1,x2,x3) produces 21 | % the same result as [X2,X1,X3] = MESHGRID(x2,x1,x3)). Because of 22 | % this, NDGRID is better suited to N-D problems that aren't spatially 23 | % based, while MESHGRID is better suited to problems in cartesian 24 | % space (2-D or 3-D). 25 | % 26 | % This is a drop-in replacement for the MATLAB version in elmat, which is 27 | % relatively slow for big grids. Note that this function only works up 28 | % to 5 dimensions 29 | % 30 | % See also MESHGRID, INTERPN. 31 | 32 | % Copyright(C) 2010, Jan-Mathijs Schoffelen, DCCN 33 | % 34 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 35 | % for the documentation and details. 36 | % 37 | % FieldTrip is free software: you can redistribute it and/or modify 38 | % it under the terms of the GNU General Public License as published by 39 | % the Free Software Foundation, either version 3 of the License, or 40 | % (at your option) any later version. 41 | % 42 | % FieldTrip is distributed in the hope that it will be useful, 43 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 44 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 45 | % GNU General Public License for more details. 46 | % 47 | % You should have received a copy of the GNU General Public License 48 | % along with FieldTrip. If not, see . 49 | % 50 | % $Id$ 51 | 52 | if nargin==0 53 | error('MATLAB:ndgrid:NotEnoughInputs', 'Not enough input arguments.'); 54 | end 55 | if nargin==1, varargin = repmat(varargin,[1 max(nargout,2)]); end 56 | 57 | ndims = numel(varargin); 58 | switch ndims 59 | case 2 60 | ones1 = ones(1,numel(varargin{1})); 61 | ones2 = ones(1,numel(varargin{2})); 62 | 63 | x = varargin{1}(:); 64 | y = varargin{2}(:)'; 65 | 66 | varargout{1} = x(:, ones2); 67 | varargout{2} = y(ones1, :); 68 | case 3 69 | ones1 = ones(1,numel(varargin{1})); 70 | ones2 = ones(1,numel(varargin{2})); 71 | ones3 = ones(1,numel(varargin{3})); 72 | 73 | x = varargin{1}(:); 74 | y = varargin{2}(:)'; 75 | z = zeros(1,1,numel(varargin{3})); 76 | z(:) = varargin{3}; 77 | 78 | varargout{1} = x(:, ones2, ones3); 79 | varargout{2} = y(ones1, :, ones3); 80 | varargout{3} = z(ones1, ones2, :); 81 | case 4 82 | ones1 = ones(1,numel(varargin{1})); 83 | ones2 = ones(1,numel(varargin{2})); 84 | ones3 = ones(1,numel(varargin{3})); 85 | ones4 = ones(1,numel(varargin{4})); 86 | 87 | x = varargin{1}(:); 88 | y = varargin{2}(:)'; 89 | z = zeros(1,1,numel(varargin{3})); 90 | z(:) = varargin{3}; 91 | xx = zeros(1,1,1,numel(varargin{4})); 92 | xx(:) = varargin{4}; 93 | 94 | varargout{1} = x(:, ones2, ones3, ones4); 95 | varargout{2} = y(ones1, :, ones3, ones4); 96 | varargout{3} = z(ones1, ones2, :, ones4); 97 | varargout{4} = xx(ones1, ones2, ones3, :); 98 | case 5 99 | ones1 = ones(1,numel(varargin{1})); 100 | ones2 = ones(1,numel(varargin{2})); 101 | ones3 = ones(1,numel(varargin{3})); 102 | ones4 = ones(1,numel(varargin{4})); 103 | ones5 = ones(1,numel(varargin{5})); 104 | 105 | x = varargin{1}(:); 106 | y = varargin{2}(:)'; 107 | z = zeros(1,1,numel(varargin{3})); 108 | z(:) = varargin{3}; 109 | xx = zeros(1,1,1,numel(varargin{4})); 110 | xx(:) = varargin{4}; 111 | yy = zeros(1,1,1,1,numel(varargin{5})); 112 | yy(:) = varargin{5}; 113 | 114 | varargout{1} = x(:, ones2, ones3, ones4, ones5); 115 | varargout{2} = y(ones1, :, ones3, ones4, ones5); 116 | varargout{3} = z(ones1, ones2, :, ones4, ones5); 117 | varargout{4} = xx(ones1, ones2, ones3, :,ones5); 118 | varargout{5} = yy(ones1, ones2, ones3, :,ones5); 119 | otherwise 120 | error('this version of ndgrid supports inputs up to 5 dimensions'); 121 | %call the ndgrid from elmat 122 | %FIXME this has to be done 123 | end 124 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/pos2transform.m: -------------------------------------------------------------------------------- 1 | function [transform] = pos2transform(pos, dim) 2 | 3 | % POS2TRANSFORM reconstructs a transformation matrix from an ordered list 4 | % of positions. 5 | % 6 | % Use as 7 | % [transform] = pos2transform(pos, dim) where pos is an ordered list of positions 8 | % and should specify a full 3D volume 9 | % 10 | % The output transform is a 4x4 homogenous transformation matrix which transforms 11 | % from 'voxelspace' into the positions provided in the input 12 | % 13 | % See also POS2DIM 14 | 15 | % Copyright (C) 2009, Jan-Mathijs Schoffelen 16 | 17 | if nargin>1, 18 | % do nothing 19 | else 20 | dim = pos2dim(pos); 21 | end 22 | x = 1:dim(1); 23 | y = 1:dim(2); 24 | z = 1:dim(3); 25 | [X,Y,Z] = ndgrid(x, y, z); 26 | ind = [X(:) Y(:) Z(:)]; 27 | ind = ind';ind(4,:) = 1; 28 | pos = pos';pos(4,:) = 1; 29 | 30 | % build in some robustness against nans 31 | sel = sum(isfinite(pos))==4; 32 | 33 | transform = pos(:,sel)/ind(:,sel); 34 | 35 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/read_asa.m: -------------------------------------------------------------------------------- 1 | function [val] = read_asa(filename, elem, format, number, token) 2 | 3 | % READ_ASA reads a specified element from an ASA file 4 | % 5 | % val = read_asa(filename, element, type, number) 6 | % 7 | % where the element is a string such as 8 | % NumberSlices 9 | % NumberPositions 10 | % Rows 11 | % Columns 12 | % etc. 13 | % 14 | % and format specifies the datatype according to 15 | % %d (integer value) 16 | % %f (floating point value) 17 | % %s (string) 18 | % 19 | % number is optional to specify how many lines of data should be read 20 | % The default is 1 for strings and Inf for numbers. 21 | % 22 | % token is optional to specifiy a character that separates the values from 23 | % anything not wanted. 24 | 25 | % Copyright (C) 2002-2012, Robert Oostenveld 26 | % 27 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 28 | % for the documentation and details. 29 | % 30 | % FieldTrip is free software: you can redistribute it and/or modify 31 | % it under the terms of the GNU General Public License as published by 32 | % the Free Software Foundation, either version 3 of the License, or 33 | % (at your option) any later version. 34 | % 35 | % FieldTrip is distributed in the hope that it will be useful, 36 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 37 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 38 | % GNU General Public License for more details. 39 | % 40 | % You should have received a copy of the GNU General Public License 41 | % along with FieldTrip. If not, see . 42 | % 43 | % $Id$ 44 | 45 | fid = fopen(filename, 'rt'); 46 | if fid==-1 47 | error(sprintf('could not open file %s', filename)); 48 | end 49 | 50 | if nargin<4 51 | if strcmp(format, '%s') 52 | number = 1; 53 | else 54 | number = Inf; 55 | end 56 | end 57 | 58 | if nargin<5 59 | token = ''; 60 | end 61 | 62 | 63 | val = []; 64 | elem = strtrim(lower(elem)); 65 | 66 | while (1) 67 | line = fgetl(fid); 68 | if ~isempty(line) && isequal(line, -1) 69 | % prematurely reached end of file 70 | fclose(fid); 71 | return 72 | end 73 | line = strtrim(line); 74 | lower_line = lower(line); 75 | if strmatch(elem, lower_line) 76 | data = line((length(elem)+1):end); 77 | break 78 | end 79 | end 80 | 81 | while isempty(data) 82 | line = fgetl(fid); 83 | if isequal(line, -1) 84 | % prematurely reached end of file 85 | fclose(fid); 86 | return 87 | end 88 | data = strtrim(line); 89 | end 90 | 91 | if strcmp(format, '%s') 92 | if number==1 93 | % interpret the data as a single string, create char-array 94 | val = detoken(strtrim(data), token); 95 | if val(1)=='=' 96 | val = val(2:end); % remove the trailing = 97 | end 98 | fclose(fid); 99 | return 100 | end 101 | % interpret the data as a single string, create cell-array 102 | val{1} = detoken(strtrim(data), token); 103 | count = 1; 104 | % read the remaining strings 105 | while count. 25 | % 26 | % $Id$ 27 | 28 | if nargin == 1 29 | outfile = []; 30 | end %if 31 | 32 | fid = fopen(filename, 'r', 'b'); 33 | version = fread(fid, 1, '*uint32'); 34 | timestamp = fread(fid, 1, '*int32'); 35 | checksum = fread(fid, 1, '*int32'); 36 | nPoints = fread(fid, 1, '*int32'); 37 | 38 | firstIndexPoint = fread(fid, [3, 5], 'double')'; 39 | 40 | points = fread(fid, [3, double(nPoints)], 'double'); 41 | 42 | fclose(fid); 43 | 44 | if(nargout > 0) 45 | output = points'; 46 | end %if 47 | 48 | if(nargin == 2) 49 | fid = fopen(outfile, 'wt'); 50 | fprintf(fid, '%d\n', nPoints); 51 | for i = 1:size(points, 2) 52 | fprintf(fid, '%.3f\t%.3f\t%.3f\n', points(1, i), points(2, i), points(3, i)); 53 | end %for 54 | fclose(fid); 55 | 56 | end %if 57 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/read_caret_spec.m: -------------------------------------------------------------------------------- 1 | function [spec, headerinfo] = read_caret_spec(specfile) 2 | 3 | % READ_CARET_SPEC reads in a caret .spec file. 4 | % 5 | % Use as 6 | % [spec, headerinfo] = read_caret_spec(specfile) 7 | % 8 | % Output arguments: 9 | % spec = structure containing per file type the files listed 10 | % headerinfo = structure containing the specfile header 11 | % 12 | % The file can be an xml-file or an ascii formatted file 13 | 14 | % Copyright (C) 2013, Jan-Mathijs Schoffelen 15 | 16 | try, 17 | % read xml-file that contains a description to a bunch of files 18 | % belonging together 19 | ft_hastoolbox('gifti', 1); 20 | g = xmltree(specfile); 21 | 22 | % convert into a structure 23 | s = convert(g); 24 | 25 | if isfield(s, 'FileHeader') 26 | headerinfo = s.FileHeader; 27 | spec = rmfield(s, 'FileHeader'); 28 | else 29 | headerinfo = []; 30 | spec = s; 31 | end 32 | 33 | % process the headerinfo 34 | if ~isempty(headerinfo) 35 | if isfield(headerinfo, 'Element') 36 | tmp = headerinfo.Element; 37 | tmp2 = struct([]); 38 | for k = 1:numel(headerinfo.Element) 39 | tmp2(1).(strrep(headerinfo.Element{k}.Name, '-', '_')) = headerinfo.Element{k}.Value; 40 | end 41 | headerinfo = tmp2; 42 | end 43 | end 44 | 45 | % further process the fields in spec 46 | f = fieldnames(spec); 47 | 48 | for k = 1:numel(f) 49 | if isempty(strfind(f{k}, 'study_metadata')) 50 | if iscell(spec.(f{k})) 51 | tmp = spec.(f{k}); 52 | tmp2 = {}; 53 | for m = 1:numel(tmp) 54 | tmpx = tmp{m}; 55 | if isstruct(tmpx) 56 | fn = fieldnames(tmpx) 57 | for i = 1:numel(fn) 58 | tmp2{end+1,1} = tmpx.(fn{i}); 59 | end 60 | end 61 | end 62 | spec.(f{k}) = tmp2; 63 | elseif isstruct(spec.(f{k})) 64 | tmp = spec.(f{k}); 65 | fn = fieldnames(tmp); 66 | tmp2 = {}; 67 | for m = 1:numel(fn) 68 | tmp2{end+1,1} = tmp.(fn{m}); 69 | end 70 | spec.(f{k}) = tmp2; 71 | else 72 | % don't know what to do with it 73 | spec = rmfield(spec, f{k}); 74 | end 75 | else 76 | % don't know what to do with it 77 | spec = rmfield(spec, f{k}); 78 | end 79 | end 80 | 81 | catch 82 | 83 | % process as ASCII-file 84 | fid = fopen(specfile); 85 | line = 'some text'; 86 | while isempty(strfind(line, 'EndHeader')) 87 | line = fgetl(fid); 88 | if isempty(strfind(line, 'BeginHeader')) && isempty(strfind(line, 'EndHeader')) 89 | tok = tokenize(line, ' '); 90 | headerinfo.(strrep(tok{1},'-','_')) = tok{2}; 91 | end 92 | end 93 | line = fgetl(fid); % empty line 94 | 95 | spec = struct([]); 96 | while 1 97 | line = fgetl(fid); 98 | if ~ischar(line), break, end 99 | tok = tokenize(line, ' '); 100 | if ~isempty(tok{1}) 101 | if isfield(spec, tok{1}) 102 | spec(1).(tok{1}){end+1,1} = tok{2}; 103 | else 104 | spec(1).(tok{1}){1} = tok{2}; 105 | end 106 | end 107 | end 108 | fclose(fid); 109 | end 110 | 111 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/read_ctf_pos.m: -------------------------------------------------------------------------------- 1 | function [fid, pnt, label] = read_ctf_pos(filename) 2 | 3 | % READ_CTF_POS reads Polhemus file created with the CTF digitizer application 4 | % 5 | % Use as 6 | % [fid, pnt, label] = read_ctf_pos(filename) 7 | % Input: 8 | % filename - Polhemus ASCII file containing digitized points 9 | % 10 | % Output: 11 | % fid - fiducial locations of fiducials 12 | % pnt - sensor/headshape locations 13 | % label - labels of the fiducials 14 | % 15 | % IMPORTANT: Note that Polhemus data files should be -ASCII files with 16 | % extension .pos generated by the CTF digitizer 17 | 18 | % Copyright (C) 2012: Jan-Mathijs Schoffelen 19 | % $Id$ 20 | 21 | [pth,nam,ext] = fileparts(filename); 22 | if ~strcmp(ext,'.pos') 23 | warndlg(sprintf('Wrong input file format\n')); 24 | return 25 | end 26 | 27 | fid = fopen(filename, 'r'); 28 | data = textscan(fid, '%s%f%f%f','headerlines',1); 29 | fclose(fid); 30 | 31 | label = data{1}; 32 | pnt = cat(2, data{2:end}); 33 | 34 | isfid = false(1,numel(label)); 35 | for k = 1:numel(label) 36 | if any(strcmpi(label{k},{'Rcoil','Lcoil','nasion','left','right','lpa','rpa','nas','rc','lc'})) 37 | isfid(k) = true; 38 | end 39 | end 40 | fid = pnt(isfid,:); 41 | label = label(isfid); 42 | pnt = pnt(~isfid,:); 43 | 44 | % average the double occurrences 45 | [u,i1,i2] = unique(label); 46 | newlabel = cell(numel(i1),1); 47 | newfid = zeros(numel(i1),3); 48 | for k = 1:numel(i1) 49 | newlabel{k} = u{k}; 50 | newfid(k,:) = mean(fid(i2==k,:),1); 51 | end 52 | fid = newfid; 53 | label = newlabel; 54 | 55 | % rename the fiducials into lpa/rpa/nasion 56 | for k = 1:numel(label) 57 | if any(strcmpi(label{k}, {'nasion' 'nose' 'nz'})) 58 | label{k} = 'nas'; 59 | end 60 | if any(strcmpi(label{k}, {'left'})) 61 | label{k} = 'lpa'; 62 | end 63 | if any(strcmpi(label{k}, {'right'})) 64 | label{k} = 'rpa'; 65 | end 66 | if any(strcmpi(label{k}, {'rc'})) 67 | label{k} = 'Rcoil'; 68 | end 69 | if any(strcmpi(label{k}, {'lc'})) 70 | label{k} = 'Lcoil'; 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/read_ctf_shape.m: -------------------------------------------------------------------------------- 1 | function [shape] = read_ctf_shape(filename); 2 | 3 | % READ_CTF_SHAPE reads headshape points and header information 4 | % from a CTF *.shape teh accompanying *.shape_info file. 5 | % 6 | % Use as 7 | % [shape] = read_ctf_shape(filename) 8 | % where filename should have the .shape extension 9 | 10 | % Copyright (C) 2003, Robert Oostenveld 11 | % 12 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 13 | % for the documentation and details. 14 | % 15 | % FieldTrip is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % FieldTrip is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with FieldTrip. If not, see . 27 | % 28 | % $Id$ 29 | 30 | shape = read_ctf_ascii([filename '_info']); 31 | 32 | if ~strcmp(shape.MRI_Info.COORDINATES, 'HEAD') 33 | warning('points on head shape are NOT in headcoordinates') 34 | end 35 | 36 | fid = fopen(filename, 'rt'); 37 | num = fscanf(fid, '%d', 1); 38 | shape.pos = fscanf(fid, '%f', inf); 39 | shape.pos = reshape(shape.pos, [3 num])'; 40 | fclose(fid); 41 | 42 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/read_off.m: -------------------------------------------------------------------------------- 1 | function [pnt, tri] = read_off(fn); 2 | 3 | % READ_OFF reads vertices and triangles from a OFF format triangulation file 4 | % 5 | % [pnt, tri] = read_off(filename) 6 | % 7 | % See also READ_TRI, READ_BND 8 | 9 | % Copyright (C) 1998, Robert Oostenveld 10 | % 11 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 12 | % for the documentation and details. 13 | % 14 | % FieldTrip is free software: you can redistribute it and/or modify 15 | % it under the terms of the GNU General Public License as published by 16 | % the Free Software Foundation, either version 3 of the License, or 17 | % (at your option) any later version. 18 | % 19 | % FieldTrip is distributed in the hope that it will be useful, 20 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | % GNU General Public License for more details. 23 | % 24 | % You should have received a copy of the GNU General Public License 25 | % along with FieldTrip. If not, see . 26 | % 27 | % $Id$ 28 | 29 | fid = fopen(fn, 'rt'); 30 | if fid~=-1 31 | 32 | % scan the file type 33 | [s, count] = fscanf(fid, '%s\n', 1); 34 | if ~strcmp(s,'OFF') 35 | msg = sprintf('wrong file type %s', s); 36 | error(msg); 37 | end 38 | 39 | % read the number of vertex points and triangles 40 | [val, count] = fscanf(fid, '%d', 3); 41 | Npnt = val(1) 42 | Ntri = val(2) 43 | 44 | % read the vertex points 45 | pnt = fscanf(fid, '%f', [3, Npnt]); 46 | pnt = pnt(1:3,:)'; 47 | 48 | % read the triangles 49 | tri = fscanf(fid, '%d', [4, Ntri]); 50 | tri = (tri(2:4,:)+1)'; 51 | fclose(fid); 52 | 53 | else 54 | error('unable to open file'); 55 | end 56 | 57 | 58 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/read_polhemus_fil.m: -------------------------------------------------------------------------------- 1 | function [fid, sens, label] = read_polhemus_fil(Fname_pol,skip) 2 | 3 | % Reads Polhemus files: 4 | % either sensor file or headshape file or both 5 | % 6 | % FORMAT [fid, sens, label] = read_polhemus_fil(Fname_pol,skip) 7 | % Input: 8 | % Fname_pol - Polhemus ASCII file containing sensor locations (cm) 9 | % (headshape can also be considered here instead of sensors) 10 | % skip - first channels to skip 11 | % 12 | % Output: 13 | % fid - fiducial locations (mm) in rows 14 | % sens - sensor/headshape locations (mm) in rows 15 | % label - labels of the fiducials 16 | % 17 | % IMPORTANT: Note that Polhemus data files should be -ASCII files with 18 | % extension .pol 19 | % It is assumed that the .pol file contains the location (cm) of fiducials 20 | % (sampled twice), possibly followed by some additional named points and 21 | % then unnamed location of the sensors. In some instances the first 22 | % few channel locations may pertain to reference channels; the skip 23 | % variable allows these to be skipped if necessary. The fiducial locations 24 | % are flaged with the strings 'NZ','LE' and 'RE'; indicating the Nasion, 25 | % left and right eare respectively. 26 | % _________________________________________________________________________ 27 | % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging 28 | 29 | % Jeremie Mattout 30 | % $Id$ 31 | 32 | % checks and assigments 33 | %-------------------------------------------------------------------------- 34 | try, skip; catch, skip = 0; end 35 | 36 | [pth,nam,ext] = fileparts(Fname_pol); 37 | if ~strcmp(ext,'.pol') 38 | warndlg(sprintf('Wrong input file format\n')); 39 | return 40 | end 41 | 42 | % --- READ Polhemus Sensor + fiducial locations --- 43 | %========================================================================== 44 | try 45 | file = textread(Fname_pol,'%s'); 46 | catch 47 | file = textread(fullfile(pwd,[nam ext]),'%s'); 48 | end 49 | % remove zeros at the end 50 | bool = 0; 51 | while bool == 0 52 | if strcmp(file{end},'0') 53 | file = file(1:end-1); 54 | else 55 | bool = 1; 56 | end 57 | end 58 | 59 | % read fiducials 60 | %-------------------------------------------------------------------------- 61 | NZ = []; 62 | LE = []; 63 | RE = []; 64 | label = {}; 65 | fid = []; 66 | temp = 0; 67 | nl = 1; 68 | 69 | while temp == 0 70 | if strcmp(file{nl},'NZ') 71 | NZ = [NZ ; str2num(file{nl+1}) str2num(file{nl+2}) str2num(file{nl+3}) ]; 72 | nl = nl + 4; 73 | elseif strcmp(file{nl},'LE') | strcmp(file{nl},'OG') 74 | LE = [LE ; str2num(file{nl+1}) str2num(file{nl+2}) str2num(file{nl+3}) ]; 75 | nl = nl + 4; 76 | elseif strcmp(file{nl},'RE') | strcmp(file{nl},'OD') 77 | RE = [RE ; str2num(file{nl+1}) str2num(file{nl+2}) str2num(file{nl+3}) ]; 78 | nl = nl + 4; 79 | elseif isempty(str2num(file{nl})) % Add possible other named points 80 | label = [label, file(nl)]; 81 | fid = [fid; str2num(file{nl+1}) str2num(file{nl+2}) str2num(file{nl+3}) ]; 82 | nl = nl + 4; 83 | else 84 | temp = 1; 85 | end 86 | end 87 | 88 | % convert from cm to mm 89 | %-------------------------------------------------------------------------- 90 | NZ = mean(NZ,1); LE = mean(LE,1); RE = mean(RE,1); 91 | fid = [NZ; LE; RE; fid]; 92 | 93 | label = [{'nas', 'lpa', 'rpa'}, label]; 94 | 95 | % read sensor locations or headshape locations 96 | %-------------------------------------------------------------------------- 97 | sens = []; 98 | start = nl + skip*3; 99 | for i = start:3:length(file) 100 | sens = [sens; str2num(file{i}) str2num(file{i+1}) str2num(file{i+2})]; 101 | end 102 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/read_stl.m: -------------------------------------------------------------------------------- 1 | function [pnt, tri, nrm] = read_stl(filename) 2 | 3 | % READ_STL reads a triangulation from an ascii or binary *.stl file, which 4 | % is a file format native to the stereolithography CAD software created by 5 | % 3D Systems. 6 | % 7 | % Use as 8 | % [pnt, tri, nrm] = read_stl(filename) 9 | % 10 | % The format is described at http://en.wikipedia.org/wiki/STL_(file_format) 11 | % 12 | % See also WRITE_STL 13 | 14 | % Copyright (C) 2006-2011, Robert Oostenveld 15 | % 16 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 17 | % for the documentation and details. 18 | % 19 | % FieldTrip is free software: you can redistribute it and/or modify 20 | % it under the terms of the GNU General Public License as published by 21 | % the Free Software Foundation, either version 3 of the License, or 22 | % (at your option) any later version. 23 | % 24 | % FieldTrip is distributed in the hope that it will be useful, 25 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | % GNU General Public License for more details. 28 | % 29 | % You should have received a copy of the GNU General Public License 30 | % along with FieldTrip. If not, see . 31 | % 32 | % $Id$ 33 | 34 | fid = fopen(filename, 'rt'); 35 | 36 | % read a small section to determine whether it is ascii or binary 37 | % a binary STL file has an 80 byte asci header, followed by non-printable characters 38 | 39 | section = fread(fid, 160, 'uint8'); 40 | fseek(fid, 0, 'bof'); 41 | 42 | if printableascii(section) 43 | % the first 160 characters are printable ascii, so assume it is an ascii format 44 | 45 | % solid testsphere 46 | % facet normal -0.13 -0.13 -0.98 47 | % outer loop 48 | % vertex 1.50000 1.50000 0.00000 49 | % vertex 1.50000 1.11177 0.05111 50 | % vertex 1.11177 1.50000 0.05111 51 | % endloop 52 | % endfacet 53 | % ... 54 | 55 | ntri = 0; 56 | while ~feof(fid) 57 | line = fgetl(fid); 58 | ntri = ntri + ~isempty(findstr('facet normal', line)); 59 | end 60 | fseek(fid, 0, 'bof'); 61 | 62 | tri = zeros(ntri,3); 63 | nrm = zeros(ntri,3); 64 | pnt = zeros(ntri*3,3); 65 | 66 | line = fgetl(fid); 67 | name = sscanf(line, 'solid %s'); 68 | 69 | for i=1:ntri 70 | line1 = fgetl(fid); 71 | line2 = fgetl(fid); % outer loop 72 | line3 = fgetl(fid); 73 | line4 = fgetl(fid); 74 | line5 = fgetl(fid); 75 | line6 = fgetl(fid); % endloop 76 | line7 = fgetl(fid); % endfacet 77 | i1 = (i-1)*3+1; 78 | i2 = (i-1)*3+2; 79 | i3 = (i-1)*3+3; 80 | tri(i,:) = [i1 i2 i3]; 81 | dum = sscanf(strtrim(line1), 'facet normal %f %f %f'); nrm(i,:) = dum(:)'; 82 | dum = sscanf(strtrim(line3), 'vertex %f %f %f'); pnt(i1,:) = dum(:)'; 83 | dum = sscanf(strtrim(line4), 'vertex %f %f %f'); pnt(i2,:) = dum(:)'; 84 | dum = sscanf(strtrim(line5), 'vertex %f %f %f'); pnt(i3,:) = dum(:)'; 85 | end 86 | 87 | else 88 | % reopen the file in binary mode, which does not make a difference on 89 | % UNIX but it does on windows 90 | fclose(fid); 91 | fid = fopen(filename, 'rb'); 92 | 93 | fseek(fid, 80, 'bof'); % skip the ascii header 94 | ntri = fread(fid, 1, 'uint32'); 95 | tri = reshape(1:(ntri*3),[3 ntri])'; 96 | tmp = fread(fid, [12 ntri], '12*float32', 2); % read 12 floats at a time, and skip 2 bytes. 97 | nrm = tmp(1:3,:)'; 98 | 99 | tmp = reshape(tmp(4:end,:),[3 3 ntri]); % position info 100 | tmp = permute(tmp,[2 3 1]); 101 | pnt = reshape(tmp, [], 3); 102 | 103 | % the above replaces the below, which is much slower, because it is using 104 | % a for loop across triangles 105 | % tri = zeros(ntri,3); 106 | % nrm = zeros(ntri,3); 107 | % pnt = zeros(ntri*3,3); 108 | % attr = zeros(ntri,1); 109 | % for i=1:ntri 110 | % i1 = (i-1)*3+1; 111 | % i2 = (i-1)*3+2; 112 | % i3 = (i-1)*3+3; 113 | % tri(i,:) = [i1 i2 i3]; 114 | % nrm(i,:) = fread(fid, 3, 'float32'); 115 | % pnt(i1,:) = fread(fid, 3, 'float32'); 116 | % pnt(i2,:) = fread(fid, 3, 'float32'); 117 | % pnt(i3,:) = fread(fid, 3, 'float32'); 118 | % attr(i) = fread(fid, 1, 'uint16'); % Attribute byte count, don't know what it is 119 | % end % for each triangle 120 | end 121 | 122 | fclose(fid); 123 | 124 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 125 | % SUBFUNCTION 126 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 127 | 128 | function retval = printableascii(num) 129 | % Codes 20hex (32dec) to 7Ehex (126dec), known as the printable characters, 130 | % represent letters, digits, punctuation marks, and a few miscellaneous 131 | % symbols. There are 95 printable characters in total. 132 | num = double(num); 133 | num(num==double(sprintf('\n'))) = double(sprintf(' ')); 134 | num(num==double(sprintf('\r'))) = double(sprintf(' ')); 135 | num(num==double(sprintf('\t'))) = double(sprintf(' ')); 136 | retval = all(num>=32 & num<=126); 137 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/read_vtk.m: -------------------------------------------------------------------------------- 1 | function [pnt, tri] = read_vtk(fn) 2 | 3 | % READ_VTK reads a triangulation from a VTK (Visualisation ToolKit) format file 4 | % Supported are triangles. 5 | % 6 | % Use as 7 | % [pnt, tri] = read_vtk(filename) 8 | % 9 | % See also WRITE_VTK 10 | 11 | % Copyright (C) 2002, Robert Oostenveld 12 | % 13 | % $Id$ 14 | 15 | fid = fopen(fn, 'rt'); 16 | if fid~=-1 17 | 18 | npnt = 0; 19 | while (~npnt) 20 | line = fgetl(fid); 21 | if ~isempty(findstr(line, 'POINTS')) 22 | npnt = sscanf(line, 'POINTS %d float'); 23 | end 24 | end 25 | pnt = zeros(npnt, 3); 26 | for i=1:npnt 27 | pnt(i,:) = fscanf(fid, '%f', 3)'; 28 | end 29 | 30 | ntri = 0; 31 | while (~ntri) 32 | line = fgetl(fid); 33 | if ~isempty(findstr(line, 'POLYGONS')) 34 | tmp = sscanf(line, 'POLYGONS %d %d'); 35 | ntri = tmp(1); 36 | end 37 | end 38 | tri = zeros(ntri, 4); 39 | for i=1:ntri 40 | tri(i,:) = fscanf(fid, '%d', 4)'; 41 | end 42 | tri = tri(:,2:4) + 1; 43 | 44 | fclose(fid); 45 | 46 | else 47 | error('unable to open file'); 48 | end 49 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/removefields.m: -------------------------------------------------------------------------------- 1 | function [s] = removefields(s, fields) 2 | 3 | % REMOVEFIELDS makes a selection of the fields in a structure 4 | % 5 | % Use as 6 | % s = removefields(s, fields); 7 | % 8 | % See also KEEPFIELDS, COPYFIELDS 9 | 10 | % Copyright (C) 2014, Robert Oostenveld 11 | % 12 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 13 | % for the documentation and details. 14 | % 15 | % FieldTrip is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % FieldTrip is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with FieldTrip. If not, see . 27 | % 28 | % $Id$ 29 | 30 | if isempty(s) 31 | % this prevents problems if s is an empty double, i.e. [] 32 | return 33 | end 34 | 35 | if ischar(fields) 36 | fields = {fields}; 37 | elseif ~iscell(fields) 38 | error('fields input argument must be a cell array of strings or a single string'); 39 | end 40 | 41 | fields = intersect(fieldnames(s), fields); 42 | for i=1:numel(fields) 43 | s = rmfield(s, fields{i}); 44 | end 45 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/renamefields.m: -------------------------------------------------------------------------------- 1 | function b = renamefields(a, old, new) 2 | 3 | % RENAMEFIELDS renames a selection of the fields in a structure 4 | % 5 | % Use as 6 | % b = renamefields(a, old, new); 7 | % which renames the fields with the old name to the new name. Fields that 8 | % are specified but not present will be silently ignored. 9 | % 10 | % See also COPYFIELDS, KEEPFIELDS, REMOVEFIELDS 11 | 12 | % Copyright (C) 2014, Robert Oostenveld 13 | % 14 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 15 | % for the documentation and details. 16 | % 17 | % FieldTrip is free software: you can redistribute it and/or modify 18 | % it under the terms of the GNU General Public License as published by 19 | % the Free Software Foundation, either version 3 of the License, or 20 | % (at your option) any later version. 21 | % 22 | % FieldTrip is distributed in the hope that it will be useful, 23 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | % GNU General Public License for more details. 26 | % 27 | % You should have received a copy of the GNU General Public License 28 | % along with FieldTrip. If not, see . 29 | % 30 | % $Id$ 31 | 32 | if isempty(a) 33 | % this prevents problems if a is an empty double, i.e. [] 34 | return 35 | end 36 | 37 | % these should be cell-arrays 38 | if ischar(old) 39 | old = {old}; 40 | end 41 | if ischar(new) 42 | new = {new}; 43 | end 44 | 45 | if length(old)~=length(new) 46 | error('the number of field names does not match between old and new'); 47 | end 48 | 49 | % keep the fields that were not mentioned 50 | b = keepfields(a, setdiff(fieldnames(a), old)); 51 | % copy the fields over with their new name 52 | for i=1:length(old) 53 | if isfield(a, old{i}); 54 | b.(new{i}) = a.(old{i}); 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/sn2individual.m: -------------------------------------------------------------------------------- 1 | function [warped]= sn2individual(P, input) 2 | 3 | % SN2INDIVIDUAL warps the input coordinates (defined as Nx3 matrix) from 4 | % normalised MNI coordinates to individual headspace coordinates, using the 5 | % warp parameters defined in the structure spmparams. 6 | % 7 | % this is modified from code from nutmeg: nut_mni2mri, which was itself 8 | % modified from code originally written by John Ashburner: 9 | % http://www.sph.umich.edu/~nichols/JG2/get_orig_coord2.m 10 | 11 | % Copyright (C) 2013, Jan-Mathijs Schoffelen 12 | % 13 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 14 | % for the documentation and details. 15 | % 16 | % FieldTrip is free software: you can redistribute it and/or modify 17 | % it under the terms of the GNU General Public License as published by 18 | % the Free Software Foundation, either version 3 of the License, or 19 | % (at your option) any later version. 20 | % 21 | % FieldTrip is distributed in the hope that it will be useful, 22 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | % GNU General Public License for more details. 25 | % 26 | % You should have received a copy of the GNU General Public License 27 | % along with FieldTrip. If not, see . 28 | % 29 | % $Id$ 30 | 31 | if numel(P.Tr)==0, 32 | % only an affine transformation has been done 33 | T = P.VF.mat*P.Affine/(P.VG.mat); 34 | warped = ft_warp_apply(T, input); 35 | else 36 | % we need the spm_dctmtx function for the nonlinear case 37 | ft_hastoolbox('spm8', 1); 38 | 39 | dim = P.VG.dim(1:3); 40 | xyz = ft_warp_apply(inv(P.VG.mat), input); % goes into voxel coordinates 41 | 42 | basX = spm_dctmtx(dim(1), size(P.Tr,1), xyz(:,1)-1); 43 | basY = spm_dctmtx(dim(2), size(P.Tr,2), xyz(:,2)-1); 44 | basZ = spm_dctmtx(dim(3), size(P.Tr,3), xyz(:,3)-1); 45 | 46 | siz = size(P.Tr); 47 | Tr1 = reshape(P.Tr(:,:,:,1),siz(1)*siz(2),siz(3)); 48 | Tr2 = reshape(P.Tr(:,:,:,2),siz(1)*siz(2),siz(3)); 49 | Tr3 = reshape(P.Tr(:,:,:,3),siz(1)*siz(2),siz(3)); 50 | 51 | xyztmp = zeros(size(xyz)); 52 | for i=1:size(xyz,1) 53 | bx = basX(i,:); 54 | by = basY(i,:); 55 | bz = basZ(i,:); 56 | tx = reshape(Tr1*bz', siz(1), siz(2) ); 57 | ty = reshape(Tr2*bz', siz(1), siz(2) ); 58 | tz = reshape(Tr3*bz', siz(1), siz(2) ); 59 | xyztmp(i,:) = [bx*tx*by' bx*ty*by' bx*tz*by']; 60 | end 61 | 62 | T = P.VF.mat*P.Affine; 63 | warped = ft_warp_apply(T, xyz+xyztmp); 64 | end; 65 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/surf_to_tetgen.m: -------------------------------------------------------------------------------- 1 | function surf_to_tetgen(filename, nodes, elements, element_types, attributes_nodes,attributes_elements) 2 | % This function converts a triangulated mesh in FieldTrip format into a 3 | % surface structure readable by Tetgen software 4 | 5 | % Copyright Arno Jannsen, 2011 6 | 7 | %Write the node file 8 | node_filename = [filename '.node']; 9 | precision_str = '%u %.40e %.40e %.40e'; 10 | 11 | N_nodes = size(nodes,1); 12 | if(nargin > 4) 13 | N_attributes = size(attributes_nodes,2); 14 | A = [nodes attributes_nodes]; 15 | for i=1:N_attributes 16 | precision_str = [precision_str ' %.5e']; 17 | end 18 | precision_str = [precision_str '\n']; 19 | else 20 | N_attributes = 0; 21 | A = nodes; 22 | precision_str = [precision_str '\n']; 23 | end 24 | 25 | 26 | fid = fopen(node_filename, 'w'); 27 | fprintf(fid, [num2str(N_nodes) ' 3 ' num2str(N_attributes) ' 0\n']); 28 | for i=1:(N_nodes) 29 | fprintf(fid,precision_str,i,A(i,:)); 30 | end 31 | fclose(fid); 32 | 33 | %Write the poly file 34 | poly_filename = [filename '.poly']; 35 | 36 | N_elements = size(elements,1); 37 | 38 | fid = fopen(poly_filename, 'w'); 39 | fprintf(fid, ['0 3 ' num2str(N_attributes) ' 0\n']); 40 | fprintf(fid, [num2str(N_elements) ' 1\n']); 41 | for i=1:(N_elements) 42 | switch element_types(i) 43 | case 302 44 | fprintf(fid,['1 0 302 # ' num2str(i) '\n']); 45 | fprintf(fid,'3 %u %u %u\n',elements(i,:)); 46 | otherwise 47 | error('currently, only type 302 elements (triangles) are supported') 48 | end 49 | end 50 | fprintf(fid,'0\n'); 51 | if(nargin > 5) 52 | N_regions = size(attributes_elements,1); 53 | if(size(attributes_elements,2) < 5) 54 | attributes_elements = [attributes_elements, -1*ones(N_regions,1)]; 55 | end 56 | fprintf(fid,[num2str(N_regions) '\n']); 57 | for i=1:N_regions 58 | fprintf(fid,'%u %.3f %.3f %.3f %u %.2f\n',i,attributes_elements(i,:)); 59 | end 60 | else 61 | fprintf(fid,'0\n'); 62 | end 63 | fclose(fid); 64 | 65 | end 66 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/tokenize.m: -------------------------------------------------------------------------------- 1 | function [tok] = tokenize(str, sep, rep) 2 | 3 | % TOKENIZE cuts a string into pieces, returning the pieces in a cell array 4 | % 5 | % Use as 6 | % t = tokenize(str) 7 | % t = tokenize(str, sep) 8 | % t = tokenize(str, sep, rep) 9 | % where 10 | % str = the string that you want to cut into pieces 11 | % sep = the separator at which to cut (default is whitespace) 12 | % rep = whether to treat repeating separator characters as one (default is false) 13 | % 14 | % With the optional boolean flag "rep" you can specify whether repeated 15 | % separator characters should be squeezed together (e.g. multiple 16 | % spaces between two words). The default is rep=1, i.e. repeated 17 | % separators are treated as one. 18 | % 19 | % See also STRTOK, TEXTSCAN 20 | 21 | % Copyright (C) 2003-2010, Robert Oostenveld 22 | % 23 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 24 | % for the documentation and details. 25 | % 26 | % FieldTrip is free software: you can redistribute it and/or modify 27 | % it under the terms of the GNU General Public License as published by 28 | % the Free Software Foundation, either version 3 of the License, or 29 | % (at your option) any later version. 30 | % 31 | % FieldTrip is distributed in the hope that it will be useful, 32 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 33 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | % GNU General Public License for more details. 35 | % 36 | % You should have received a copy of the GNU General Public License 37 | % along with FieldTrip. If not, see . 38 | % 39 | % $Id$ 40 | 41 | % these are for remembering the type on subsequent calls with the same input arguments 42 | persistent previous_argin previous_argout 43 | 44 | str = str(:)'; 45 | 46 | if nargin<2 47 | sep = [9:13 32]; % White space characters 48 | end 49 | 50 | if nargin<3 51 | rep = false; 52 | end 53 | 54 | current_argin = {str, sep, rep}; 55 | if isequal(current_argin, previous_argin) 56 | % don't do the processing again, but return the previous values from cache 57 | tok = previous_argout; 58 | return 59 | end 60 | 61 | if numel(sep)==1 62 | f = find(str==sep); 63 | else 64 | f = find(ismember(str, sep)); 65 | end 66 | f = [0, f, length(str)+1]; 67 | 68 | tok = cell(1, length(f)-1); 69 | for i=1:(length(f)-1) 70 | tok{i} = str((f(i)+1):(f(i+1)-1)); 71 | end 72 | 73 | if rep 74 | % remove empty cells, which occur if the separator is repeated (e.g. multiple spaces) 75 | tok(cellfun('isempty', tok))=[]; 76 | end 77 | 78 | % remember the current input and output arguments, so that they can be 79 | % reused on a subsequent call in case the same input argument is given 80 | current_argout = tok; 81 | previous_argin = current_argin; 82 | previous_argout = current_argout; 83 | 84 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/write_nifti2_hdr.m: -------------------------------------------------------------------------------- 1 | function write_nifti2_hdr(filename, hdr) 2 | 3 | % WRITE_NIFTI2_HDR 4 | % 5 | % Use as 6 | % write_nifti2_hdr(filename, hdr) 7 | % where 8 | % filename = string 9 | % hdr = structure with nifti-2 header information 10 | % 11 | % See also READ_NIFTI_HDR, READ_CIFTI, WRITE_CIFTI 12 | 13 | % Copyright (C) 2013, Robert Oostenveld 14 | % 15 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 16 | % for the documentation and details. 17 | % 18 | % FieldTrip is free software: you can redistribute it and/or modify 19 | % it under the terms of the GNU General Public License as published by 20 | % the Free Software Foundation, either version 3 of the License, or 21 | % (at your option) any later version. 22 | % 23 | % FieldTrip is distributed in the hope that it will be useful, 24 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | % GNU General Public License for more details. 27 | % 28 | % You should have received a copy of the GNU General Public License 29 | % along with FieldTrip. If not, see . 30 | % 31 | % $Id$ 32 | 33 | if ischar(filename) 34 | fid = fopen(filename, 'w'); 35 | else 36 | fid = filename; 37 | end 38 | 39 | fwrite(fid, 540, 'int32'); 40 | 41 | assert(fwrite(fid, hdr.magic , 'int8' )==8 ); % 4 `n', '+', `2', `\0','\r','\n','\032','\n' or (0x6E,0x2B,0x32,0x00,0x0D,0x0A,0x1A,0x0A) 42 | assert(fwrite(fid, hdr.datatype , 'int16' )==1 ); % 12 See file formats 43 | assert(fwrite(fid, hdr.bitpix , 'int16' )==1 ); % 14 See file formats 44 | assert(fwrite(fid, hdr.dim , 'int64' )==8 ); % 16 See file formats 45 | assert(fwrite(fid, hdr.intent_p1 , 'double' )==1 ); % 80 0 46 | assert(fwrite(fid, hdr.intent_p2 , 'double' )==1 ); % 88 0 47 | assert(fwrite(fid, hdr.intent_p3 , 'double' )==1 ); % 96 0 48 | assert(fwrite(fid, hdr.pixdim , 'double' )==8 ); % 104 0,1,1,1,1,1,1,1 49 | assert(fwrite(fid, hdr.vox_offset , 'int64' )==1 ); % 168 Offset of data, minimum=544 50 | assert(fwrite(fid, hdr.scl_slope , 'double' )==1 ); % 176 1 51 | assert(fwrite(fid, hdr.scl_inter , 'double' )==1 ); % 184 0 52 | assert(fwrite(fid, hdr.cal_max , 'double' )==1 ); % 192 0 53 | assert(fwrite(fid, hdr.cal_min , 'double' )==1 ); % 200 0 54 | assert(fwrite(fid, hdr.slice_duration , 'double' )==1 ); % 208 0 55 | assert(fwrite(fid, hdr.toffset , 'double' )==1 ); % 216 0 56 | assert(fwrite(fid, hdr.slice_start , 'int64' )==1 ); % 224 0 57 | assert(fwrite(fid, hdr.slice_end , 'int64' )==1 ); % 232 0 58 | assert(fwrite(fid, hdr.descrip , 'int8' )==80); % 240 All zeros 59 | assert(fwrite(fid, hdr.aux_file , 'int8' )==24); % 320 All zeros 60 | assert(fwrite(fid, hdr.qform_code , 'int32' )==1 ); % 344 NIFTI_XFORM_UNKNOWN (0) 61 | assert(fwrite(fid, hdr.sform_code , 'int32' )==1 ); % 348 NIFTI_XFORM_UNKNOWN (0) 62 | assert(fwrite(fid, hdr.quatern_b , 'double' )==1 ); % 352 0 63 | assert(fwrite(fid, hdr.quatern_c , 'double' )==1 ); % 360 0 64 | assert(fwrite(fid, hdr.quatern_d , 'double' )==1 ); % 368 0 65 | assert(fwrite(fid, hdr.qoffset_x , 'double' )==1 ); % 376 0 66 | assert(fwrite(fid, hdr.qoffset_y , 'double' )==1 ); % 384 0 67 | assert(fwrite(fid, hdr.qOffset_z , 'double' )==1 ); % 392 0 68 | assert(fwrite(fid, hdr.srow_x , 'double' )==4 ); % 400 0,0,0,0 69 | assert(fwrite(fid, hdr.srow_y , 'double' )==4 ); % 432 0,0,0,0 70 | assert(fwrite(fid, hdr.srow_z , 'double' )==4 ); % 464 0,0,0,0 71 | assert(fwrite(fid, hdr.slice_code , 'int32' )==1 ); % 496 0 72 | assert(fwrite(fid, hdr.xyzt_units , 'int32' )==1 ); % 500 0xC (seconds, millimeters) 73 | assert(fwrite(fid, hdr.intent_code , 'int32' )==1 ); % 504 See file formats 74 | assert(fwrite(fid, hdr.intent_name , 'int8' )==16); % 508 See file formats 75 | assert(fwrite(fid, hdr.dim_info , 'int8' )==1 ); % 524 0 76 | assert(fwrite(fid, hdr.unused_str , 'int8' )==15); % 525 All zeros 77 | % disp(ftell(fid)); % 540 End of the header 78 | 79 | if ischar(filename) 80 | fclose(fid); 81 | end 82 | 83 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/write_off.m: -------------------------------------------------------------------------------- 1 | function write_off(filename, pnt, plc) 2 | 3 | % WRITE_OFF writes a set of geometrical planar forms (called piecewise linear complex, PLC) 4 | % to an ascii *.off file, which is a file format created by Princeton Shape Benchmark 5 | % 6 | % Use as 7 | % write_stl(filename, pnt, tri) 8 | % 9 | % See also READ_OFF 10 | 11 | % Copyright (C) 2010, Cristiano Micheli 12 | % 13 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 14 | % for the documentation and details. 15 | % 16 | % FieldTrip is free software: you can redistribute it and/or modify 17 | % it under the terms of the GNU General Public License as published by 18 | % the Free Software Foundation, either version 3 of the License, or 19 | % (at your option) any later version. 20 | % 21 | % FieldTrip is distributed in the hope that it will be useful, 22 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | % GNU General Public License for more details. 25 | % 26 | % You should have received a copy of the GNU General Public License 27 | % along with FieldTrip. If not, see . 28 | % 29 | % $Id$ 30 | 31 | nedges = 0; 32 | fid = fopen(filename, 'wb'); 33 | npnt = size(pnt,1); 34 | nplc = size(plc,1); 35 | 36 | % check that the indexes of plc are correct (0 convention) 37 | if ~sum(any(plc==0)) 38 | plc = plc - 1; 39 | end 40 | 41 | fprintf(fid, 'OFF\n'); 42 | fprintf(fid, '%d %d %d\n',npnt,nplc,nedges); 43 | for i=1:npnt 44 | fprintf(fid, '%f %f %f\n', pnt(i,1), pnt(i,2), pnt(i,3)); 45 | end 46 | for i=1:nplc 47 | str = '%d '; 48 | nvert = size(plc(i,:),2); 49 | str2 = 'nvert,'; 50 | for j=1:nvert 51 | str = [str '%d ']; 52 | str2 = [str2 'plc(i,' num2str(j) '),']; 53 | end 54 | str = [str '\n''']; str2 = str2(1:end-1); 55 | eval(['fprintf(fid,''' str ',' str2 ');']); 56 | end 57 | 58 | fclose(fid); 59 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/write_ply.m: -------------------------------------------------------------------------------- 1 | function write_ply(fn, pnt, tri, format) 2 | 3 | % WRITE_PLY writes triangles, tetraheders or hexaheders to a Stanford *.ply format file 4 | % 5 | % Use as 6 | % write_ply(filename, vertex, element) 7 | % 8 | % Documentation is provided on 9 | % http://paulbourke.net/dataformats/ply/ 10 | % http://en.wikipedia.org/wiki/PLY_(file_format) 11 | % 12 | % See also READ_PLY, READ_VTK, WRITE_VTK 13 | 14 | % Copyright (C) 2012, Robert Oostenveld 15 | % 16 | % $Id$ 17 | 18 | % the element are described as 19 | % Mx3 list of vertices for triangles 20 | % Mx4 list of vertices for tetraheders 21 | % Mx8 list of vertices for hexaheders 22 | 23 | if nargin<4 24 | format = 'ascii'; 25 | end 26 | 27 | if size(tri,2)==4 28 | % describe the sides of the tetraheders as polygon surface elements 29 | % see http://bugzilla.fcdonders.nl/show_bug.cgi?id=1836 30 | tri = [ 31 | tri(:,[3 2 1]) 32 | tri(:,[2 4 1]) 33 | tri(:,[3 4 2]) 34 | tri(:,[4 3 1]) 35 | ]; 36 | elseif size(tri,2)==8 37 | % describe the sides of the hexaheders as polygon surface elements 38 | % see http://bugzilla.fcdonders.nl/show_bug.cgi?id=1836 39 | tri = [ 40 | tri(:,[4 3 2 1]) 41 | tri(:,[1 2 6 5]) 42 | tri(:,[3 7 6 2]) 43 | tri(:,[4 8 7 3]) 44 | tri(:,[5 8 4 1]) 45 | tri(:,[6 7 8 5]) 46 | ]; 47 | end 48 | 49 | if strcmp(format, 'ascii') 50 | fid = fopen(fn, 'wt'); 51 | else 52 | fid = fopen(fn, 'wb'); 53 | end 54 | 55 | if fid~=-1 56 | 57 | npnt = size(pnt,1); 58 | ntri = size(tri,1); 59 | if numel(tri)>0 60 | % MATLAB indexes start at 1, inside the file they start at 0 61 | tri = tri-1; 62 | end 63 | 64 | % write the header 65 | fprintf(fid, 'ply\n'); 66 | if strcmp(format, 'ascii') 67 | fprintf(fid, 'format ascii 1.0\n'); 68 | else 69 | [c, m, e] = computer; 70 | if e=='L' 71 | fprintf(fid, 'format binary_little_endian 1.0\n'); 72 | elseif e=='B' 73 | fprintf(fid, 'format binary_big_endian 1.0\n'); 74 | end 75 | end 76 | 77 | fprintf(fid, 'element vertex %d\n', npnt); 78 | fprintf(fid, 'property float x\n'); 79 | fprintf(fid, 'property float y\n'); 80 | fprintf(fid, 'property float z\n'); 81 | fprintf(fid, 'element face %d\n', ntri); 82 | fprintf(fid, 'property list uchar int vertex_index\n'); 83 | fprintf(fid, 'end_header\n'); 84 | 85 | if strcmp(format, 'ascii') 86 | % write the vertex points 87 | fprintf(fid, '%f\t%f\t%f\n', pnt'); 88 | num = size(tri,2); 89 | switch num 90 | case 3 91 | fprintf(fid, '3\t%d\t%d\t%d\n', tri'); 92 | case 4 93 | fprintf(fid, '4\t%d\t%d\t%d\t%d\n', tri'); 94 | case 5 95 | fprintf(fid, '5\t%d\t%d\t%d\t%d\n', tri'); 96 | case 6 97 | fprintf(fid, '6\t%d\t%d\t%d\t%d\n', tri'); 98 | case 7 99 | fprintf(fid, '7\t%d\t%d\t%d\t%d\n', tri'); 100 | case 8 101 | fprintf(fid, '8\t%d\t%d\t%d\t%d\n', tri'); 102 | case 9 103 | fprintf(fid, '9\t%d\t%d\t%d\t%d\n', tri'); 104 | otherwise 105 | error('unsupported size for polygons (%d)', num); 106 | end % case 107 | else 108 | fwrite(fid, pnt', 'single'); % float 109 | num = size(tri,2); 110 | for i=1:size(tri,1) 111 | fwrite(fid, num, 'uint8'); % uchar 112 | fwrite(fid, tri(i,:), 'int32'); % int 113 | end 114 | end 115 | 116 | fclose(fid); 117 | 118 | else 119 | error('unable to open file'); 120 | end 121 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/write_stl.m: -------------------------------------------------------------------------------- 1 | function write_stl(filename, pnt, tri, nrm); 2 | 3 | % WRITE_STL writes a triangulation to an ascii *.stl file, which is a file 4 | % format native to the stereolithography CAD software created by 3D Systems. 5 | % 6 | % Use as 7 | % write_stl(filename, pnt, tri, nrm) 8 | % where nrm refers to the triangle normals. 9 | % 10 | % See also READ_STL 11 | 12 | % Copyright (C) 2006, Robert Oostenveld 13 | % 14 | % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org 15 | % for the documentation and details. 16 | % 17 | % FieldTrip is free software: you can redistribute it and/or modify 18 | % it under the terms of the GNU General Public License as published by 19 | % the Free Software Foundation, either version 3 of the License, or 20 | % (at your option) any later version. 21 | % 22 | % FieldTrip is distributed in the hope that it will be useful, 23 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | % GNU General Public License for more details. 26 | % 27 | % You should have received a copy of the GNU General Public License 28 | % along with FieldTrip. If not, see . 29 | % 30 | % $Id$ 31 | 32 | % solid testsphere 33 | % facet normal -0.13 -0.13 -0.98 34 | % outer loop 35 | % vertex 1.50000 1.50000 0.00000 36 | % vertex 1.50000 1.11177 0.05111 37 | % vertex 1.11177 1.50000 0.05111 38 | % endloop 39 | % endfacet 40 | % ... 41 | 42 | fid = fopen(filename, 'wb'); 43 | 44 | ntri = size(tri,1); 45 | fprintf(fid, 'solid unknown\n'); 46 | 47 | for i=1:ntri 48 | fprintf(fid, ' facet normal %f %f %f\n', nrm(i,:)); 49 | fprintf(fid, ' outer loop\n'); 50 | fprintf(fid, ' vertex %f %f %f\n', pnt(tri(i,1),1), pnt(tri(i,1),2), pnt(tri(i,1),3)); 51 | fprintf(fid, ' vertex %f %f %f\n', pnt(tri(i,2),1), pnt(tri(i,2),2), pnt(tri(i,2),3)); 52 | fprintf(fid, ' vertex %f %f %f\n', pnt(tri(i,3),1), pnt(tri(i,3),2), pnt(tri(i,3),3)); 53 | fprintf(fid, ' endloop\n'); 54 | fprintf(fid, ' endfacet\n'); 55 | end 56 | 57 | fprintf(fid, 'endsolid\n'); 58 | 59 | fclose(fid); 60 | 61 | -------------------------------------------------------------------------------- /Sub-function/cifti-matlab-master/private/write_vtk.m: -------------------------------------------------------------------------------- 1 | function write_vtk(fn, pnt, tri) 2 | 3 | % WRITE_VTK writes a triangulation to a VTK (Visualisation ToolKit) format file. 4 | % Supported are triangles, tetraheders and hexaheders. 5 | % 6 | % Use as 7 | % write_vtk(filename, pnt, tri) 8 | % 9 | % See also READ_VTK, WRITE_PLY 10 | 11 | % Copyright (C) 2002, Robert Oostenveld 12 | % 13 | % $Id$ 14 | 15 | fid = fopen(fn, 'wt'); 16 | if fid~=-1 17 | 18 | npnt = size(pnt,1); 19 | ntri = size(tri,1); 20 | 21 | % write the header 22 | fprintf(fid, '# vtk DataFile Version 2.0\n'); 23 | fprintf(fid, 'vtk output\n'); 24 | fprintf(fid, 'ASCII\n'); 25 | fprintf(fid, 'DATASET POLYDATA\n'); 26 | fprintf(fid, '\n'); 27 | 28 | % write the vertex points 29 | fprintf(fid, 'POINTS %d float\n', npnt); 30 | fprintf(fid, '%f\t%f\t%f\n', pnt'); 31 | fprintf(fid, '\n'); 32 | 33 | if size(tri,2)==3 34 | % write the triangles 35 | fprintf(fid, 'POLYGONS %d %d\n', ntri, (3+1)*ntri); 36 | fprintf(fid, '3\t%d\t%d\t%d\n', (tri-1)'); 37 | fprintf(fid, '\n'); 38 | elseif size(tri,2)==4 39 | % write the tetraheders 40 | fprintf(fid, 'POLYGONS %d %d\n', ntri, (4+1)*ntri); 41 | fprintf(fid, '4\t%d\t%d\t%d\t%d\n', (tri-1)'); 42 | fprintf(fid, '\n'); 43 | elseif size(tri,2)==8 44 | % write the hexaheders 45 | fprintf(fid, 'POLYGONS %d %d\n', ntri, (8+1)*ntri); 46 | fprintf(fid, '8\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n', (tri-1)'); 47 | fprintf(fid, '\n'); 48 | end 49 | 50 | fclose(fid); 51 | 52 | else 53 | error('unable to open file'); 54 | end 55 | -------------------------------------------------------------------------------- /Sub-function/emptyfile.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Sub-function/nanconv/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Benjamin Kraus 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /Sub-function/nanconv/nanconv.m: -------------------------------------------------------------------------------- 1 | function c = nanconv(a, k, varargin) 2 | % NANCONV Convolution in 1D or 2D ignoring NaNs. 3 | % C = NANCONV(A, K) convolves A and K, correcting for any NaN values 4 | % in the input vector A. The result is the same size as A (as though you 5 | % called 'conv' or 'conv2' with the 'same' shape). 6 | % 7 | % C = NANCONV(A, K, 'param1', 'param2', ...) specifies one or more of the following: 8 | % 'edge' - Apply edge correction to the output. 9 | % 'noedge' - Do not apply edge correction to the output (default). 10 | % 'nanout' - The result C should have NaNs in the same places as A. 11 | % 'nonanout' - The result C should have ignored NaNs removed (default). 12 | % Even with this option, C will have NaN values where the 13 | % number of consecutive NaNs is too large to ignore. 14 | % '2d' - Treat the input vectors as 2D matrices (default). 15 | % '1d' - Treat the input vectors as 1D vectors. 16 | % This option only matters if 'a' or 'k' is a row vector, 17 | % and the other is a column vector. Otherwise, this 18 | % option has no effect. 19 | % 20 | % NANCONV works by running 'conv2' either two or three times. The first 21 | % time is run on the original input signals A and K, except all the 22 | % NaN values in A are replaced with zeros. The 'same' input argument is 23 | % used so the output is the same size as A. The second convolution is 24 | % done between a matrix the same size as A, except with zeros wherever 25 | % there is a NaN value in A, and ones everywhere else. The output from 26 | % the first convolution is normalized by the output from the second 27 | % convolution. This corrects for missing (NaN) values in A, but it has 28 | % the side effect of correcting for edge effects due to the assumption of 29 | % zero padding during convolution. When the optional 'noedge' parameter 30 | % is included, the convolution is run a third time, this time on a matrix 31 | % of all ones the same size as A. The output from this third convolution 32 | % is used to restore the edge effects. The 'noedge' parameter is enabled 33 | % by default so that the output from 'nanconv' is identical to the output 34 | % from 'conv2' when the input argument A has no NaN values. 35 | % 36 | % See also conv, conv2 37 | % 38 | % AUTHOR: Benjamin Kraus (bkraus@bu.edu, ben@benkraus.com) 39 | % Copyright (c) 2013, Benjamin Kraus 40 | % $Id: nanconv.m 4861 2013-05-27 03:16:22Z bkraus $ 41 | 42 | % Process input arguments 43 | for arg = 1:nargin-2 44 | switch lower(varargin{arg}) 45 | case 'edge'; edge = true; % Apply edge correction 46 | case 'noedge'; edge = false; % Do not apply edge correction 47 | case {'same','full','valid'}; shape = varargin{arg}; % Specify shape 48 | case 'nanout'; nanout = true; % Include original NaNs in the output. 49 | case 'nonanout'; nanout = false; % Do not include NaNs in the output. 50 | case {'2d','is2d'}; is1D = false; % Treat the input as 2D 51 | case {'1d','is1d'}; is1D = true; % Treat the input as 1D 52 | end 53 | end 54 | 55 | % Apply default options when necessary. 56 | if(exist('edge','var')~=1); edge = false; end 57 | if(exist('nanout','var')~=1); nanout = false; end 58 | if(exist('is1D','var')~=1); is1D = false; end 59 | if(exist('shape','var')~=1); shape = 'same'; 60 | elseif(~strcmp(shape,'same')) 61 | error([mfilename ':NotImplemented'],'Shape ''%s'' not implemented',shape); 62 | end 63 | 64 | % Get the size of 'a' for use later. 65 | sza = size(a); 66 | 67 | % If 1D, then convert them both to columns. 68 | % This modification only matters if 'a' or 'k' is a row vector, and the 69 | % other is a column vector. Otherwise, this argument has no effect. 70 | if(is1D); 71 | if(~isvector(a) || ~isvector(k)) 72 | error('MATLAB:conv:AorBNotVector','A and B must be vectors.'); 73 | end 74 | a = a(:); k = k(:); 75 | end 76 | 77 | % Flat function for comparison. 78 | o = ones(size(a)); 79 | 80 | % Flat function with NaNs for comparison. 81 | on = ones(size(a)); 82 | 83 | % Find all the NaNs in the input. 84 | n = isnan(a); 85 | 86 | % Replace NaNs with zero, both in 'a' and 'on'. 87 | a(n) = 0; 88 | on(n) = 0; 89 | 90 | % Check that the filter does not have NaNs. 91 | if(any(isnan(k))); 92 | error([mfilename ':NaNinFilter'],'Filter (k) contains NaN values.'); 93 | end 94 | 95 | % Calculate what a 'flat' function looks like after convolution. 96 | if(any(n(:)) || edge) 97 | flat = conv2(on,k,shape); 98 | else flat = o; 99 | end 100 | 101 | % The line above will automatically include a correction for edge effects, 102 | % so remove that correction if the user does not want it. 103 | if(any(n(:)) && ~edge); flat = flat./conv2(o,k,shape); end 104 | 105 | % Do the actual convolution 106 | c = conv2(a,k,shape)./flat; 107 | 108 | % If requested, replace output values with NaNs corresponding to input. 109 | if(nanout); c(n) = NaN; end 110 | 111 | % If 1D, convert back to the original shape. 112 | if(is1D && sza(1) == 1); c = c.'; end 113 | 114 | end 115 | -------------------------------------------------------------------------------- /Sub-function/parcellation_template.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/parcellation_template.mat -------------------------------------------------------------------------------- /Sub-function/parcellation_template22_RightBrain_subject1-100.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/parcellation_template22_RightBrain_subject1-100.mat -------------------------------------------------------------------------------- /Sub-function/parcellation_template7.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Sub-function/parcellation_template7.mat -------------------------------------------------------------------------------- /Sub-function/preproc_fRMI.m: -------------------------------------------------------------------------------- 1 | function [sigValid,posValid,nanChans] = preproc_fRMI(data,pos,fs) ; 2 | % load in the signals from HCP and extract the valid surface cortex data 3 | % input: data from nii file; 4 | % pos from surf.nii file; 5 | % output: sigValid and posValid, valid cortex data 6 | 7 | disp('start preprocessing...'); 8 | surfData = data.dtseries ; 9 | surfPos = data.pos ; 10 | 11 | % cortex position 12 | % for i=1:21 13 | % data.brainstructurelabel{i} 14 | % end 15 | % cortex is the region we are interested but the pos is from surface.gii 16 | % file 17 | 18 | % find the cortex 19 | cortexLIdx = find(data.brainstructure == 1) ; 20 | startL = min(cortexLIdx) ; 21 | endL = max(cortexLIdx) ; 22 | cortexRIdx = find(data.brainstructure == 2) ; 23 | startR = min(cortexRIdx) ; 24 | endR = max(cortexRIdx) ; 25 | 26 | %% Get the valid region (cortex) 27 | %patch('Faces',posLC.faces,'Vertices',posLC.vertices) 28 | %axis equal 29 | rangeC = startL:endL ; % left brain 30 | % rangeC = startR:endR ; % right brain 31 | 32 | tic 33 | % check the valid region in time 34 | % figure; 35 | % plot((1:size(surfData,2))/fs,surfData(startL,:)) 36 | % hold on 37 | % plot((1:size(surfData,2))/fs,surfData(startL+1000,:)) 38 | % hold on 39 | % plot((1:size(surfData,2))/fs,surfData(startL+10000,:)) 40 | % title('check three lines of data to confirm the valid region') 41 | 42 | % get rid of the first and the last 10s 43 | % timeRange = fix(10*fs): size(surfData,2)-fix(10*fs) ; 44 | timeRange = 1: size(surfData,2) ; 45 | sigRange = surfData(rangeC,:) ; 46 | sigOri = sigRange(:,timeRange) ; 47 | % sigOri = zscore(surfData(rangeC,timeRange),[],2) ; 48 | nanChans = any(isnan(sigOri(:,:)),2); 49 | 50 | sigValid = sigOri; 51 | sigValid(nanChans,:) = [] ; 52 | posValid = pos ; 53 | posValid.vertices(nanChans,:) = [] ; 54 | 55 | % figure; 56 | % plot(posValid.vertices(1:10:end,1),posValid.vertices(1:10:end,2),'o') -------------------------------------------------------------------------------- /Sub-function/spaceFreq_fMRI.m: -------------------------------------------------------------------------------- 1 | function sigSSpec_reshape=spaceFreq_fMRI(posValid,dataIn,xCord,yCord,... 2 | flagPlotSpe, flagCheckIntp,mask) 3 | 4 | %% re-interpolate data (time consuming) 5 | [X,Y] = meshgrid(xCord, yCord); 6 | sigSSpec = dataIn ; 7 | 8 | sigSSpec_reshape = [] ; 9 | disp('start interpolation (downsample)...') 10 | tic 11 | if sum(mask(:))~= 0 12 | flagMask = 1 ; 13 | end 14 | for iTime=1:size(sigSSpec,2) 15 | % sigSSpec_reshape(:,:,iTime) = griddata(double(posValid.vertices(1:10:end,1)),... 16 | % double(posValid.vertices(1:10:end,2)),sigSSpec(1:10:end,iTime),X,Y,'cubic') ; 17 | sigSSpec_reshape(:,:,iTime) = griddata(double(posValid.vertices(:,1)),... 18 | double(posValid.vertices(:,2)),sigSSpec(:,iTime),X,Y,'cubic') ; 19 | if flagMask 20 | sigSSpec_reshape(:,:,iTime) = sigSSpec_reshape(:,:,iTime).*mask ; 21 | end 22 | end 23 | toc 24 | 25 | %% plot the spatial spectrum 26 | if flagPlotSpe 27 | [Pxx,F] = pmtm(zscore(sigSSpec_reshape(100,:,1)),[],[],1e3) ; 28 | figure; 29 | coeffs = polyfit(log(F(F>10)),log(Pxx(F>10)),1); 30 | fittedX = log(F); 31 | fittedLogY = polyval(coeffs, fittedX); 32 | fittedY = exp(fittedLogY) ; 33 | 34 | loglog(F,Pxx) 35 | hold on 36 | loglog(F,fittedY) 37 | end 38 | 39 | %% check the re-interpolation by visualisation 40 | if flagCheckIntp 41 | %% original data 42 | sigIn = sigSSpec ; % angle(sigSSpec) ; 43 | numColor = 1000 ; 44 | tempColor = jet(numColor) ; 45 | maxData = max(sigIn(:)) ; 46 | minData = min(sigIn(:)) ; 47 | colorAxis = linspace(minData,maxData/2,numColor) ; 48 | idxColor1 = zeros(size(sigIn)) ; 49 | disp('start visulisation 1 ...') 50 | tic 51 | for iTime = 1:size(sigIn,2) 52 | % [cordI,cordJ] = ind2sub(size(sigIn),iData) ; 53 | [~,idxColor1(:,iTime)] = min(abs(sigIn(:,iTime)-ones(size(sigIn,1),1)*colorAxis),[],2) ; 54 | % disp([num2str(iTime/size(sigIn,2)),'%']) 55 | end 56 | toc 57 | %% interpolated data 58 | sigIn = sigSSpec_reshape ; % angle(sigSSpec_reshape) ; % notice the size change 59 | % numColor = 1000 ; 60 | % tempColor = jet(numColor) ; 61 | % maxData = max(sigIn(:)) ; 62 | % minData = min(sigIn(:)) ; 63 | % colorAxis = linspace(minData,maxData/2,numColor) ; 64 | sigIn = reshape(sigIn,size(sigIn,1)*size(sigIn,2),size(sigIn,3)) ; 65 | idxColor2 = zeros(size(sigIn)) ; 66 | disp('start visulisation 2 ...') 67 | tic 68 | for iTime = 1:size(sigIn,2) 69 | % [cordI,cordJ] = ind2sub(size(sigIn),iData) ; 70 | [~,idxColor2(:,iTime)] = min(abs(sigIn(:,iTime)-ones(size(sigIn,1),1)*colorAxis),[],2) ; 71 | % disp([num2str(iTime/size(sigIn,2)),'%']) 72 | end 73 | toc 74 | X_list = reshape(X,size(X,1)*size(X,2),1) ; 75 | Y_list = reshape(Y,size(Y,1)*size(Y,2),1) ; 76 | 77 | iTime = 100 ; 78 | figure; 79 | scatter(posValid.vertices(:,1),posValid.vertices(:,2),4,tempColor(idxColor1(:,iTime),:)) ; 80 | xlim([xCord(1) xCord(end)]) 81 | ylim([yCord(1) yCord(end)]) 82 | 83 | figure; 84 | scatter(X_list,Y_list,4,tempColor(idxColor2(:,iTime),:)) ; 85 | 86 | 87 | end 88 | -------------------------------------------------------------------------------- /Videos/Supplementary_Video_S1.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Videos/Supplementary_Video_S1.avi -------------------------------------------------------------------------------- /Videos/Supplementary_Video_S2.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Videos/Supplementary_Video_S2.avi -------------------------------------------------------------------------------- /Videos/Supplementary_Video_S3.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Videos/Supplementary_Video_S3.avi -------------------------------------------------------------------------------- /Videos/Supplementary_Video_S4.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Videos/Supplementary_Video_S4.avi -------------------------------------------------------------------------------- /Videos/Supplementary_Video_S5.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Videos/Supplementary_Video_S5.avi -------------------------------------------------------------------------------- /Videos/Supplementary_Video_S6.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Videos/Supplementary_Video_S6.avi -------------------------------------------------------------------------------- /Videos/Video captions.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainDynamicsUSYD/BrainVortexToolbox/69d681fde5c3f3cf6508c6aeba5d7fab64373588/Videos/Video captions.docx --------------------------------------------------------------------------------