### Navigate to SPM Example Data Directory Source: https://www.fil.ion.ucl.ac.uk/spm/docs/tutorials/dcm/dcm_ir Change the current directory to where the example MEG data is stored. This is a prerequisite for loading the dataset. ```bash cd cdbespm12_SPM_CTF_MEG_example_faces1_3D.mat cdbespm12_SPM_CTF_MEG_example_faces1_3D.dat ``` -------------------------------- ### Install MATLAB Runtime via Command Line Source: https://www.fil.ion.ucl.ac.uk/spm/docs/installation/standalone Perform a non-GUI installation of the MATLAB Runtime on Linux or macOS. ```bash chmod 755 runtime_installer/Runtime_R2024b_for_spm_standalone_24.11.install runtime_installer/Runtime_R2024b_for_spm_standalone_24.11.install -agreeToLicense yes ``` -------------------------------- ### Execute SPM via Command Line Source: https://www.fil.ion.ucl.ac.uk/spm/docs/installation/standalone Start the SPM application by providing the path to the MATLAB Runtime installation. ```bash ./run_spmxx.sh /usr/local/MATLAB/MATLAB_Runtime// ``` -------------------------------- ### Install MSYS2 development tools Source: https://www.fil.ion.ucl.ac.uk/spm/docs/development/compilation/windows Use pacman to update the system and install the necessary MinGW-w64 toolchain. ```bash pacman -Syu pacman -Su pacman -S --needed base-devel mingw-w64-x86_64-toolchain ``` -------------------------------- ### MATLAB Test Class Setup Source: https://www.fil.ion.ucl.ac.uk/spm/docs/development/testing Example of using TestClassSetup to configure SPM defaults before all tests in a class run. This is useful for shared test initialization. ```matlab methods (TestClassSetup) function setupSPM(testCase) spm('defaults','fmri'); spm_jobman('initcfg'); spm_get_defaults('cmdline',true); end end ``` -------------------------------- ### Install SPM12 Desktop Entry and Icon on Linux Source: https://www.fil.ion.ucl.ac.uk/spm/docs/installation/standalone Use xdg-utils to install the created .desktop file and SPM icon for a faster launch and menu integration. ```bash xdg-desktop-menu install --novendor spm12.desktop xdg-icon-resource install --novendor --size 32 spm.png ``` -------------------------------- ### Setup workspace directories Source: https://www.fil.ion.ucl.ac.uk/spm/docs/tutorials/MEEG/meeg_firstlevel Initializes the analysis and data paths for the SPM project. ```matlab clear; cwd = pwd; workpath = fullfile(cwd, 'analysis'); datapath = fullfile(cwd, 'data'); spm_mkdir(workpath); ``` -------------------------------- ### Start Octave Source: https://www.fil.ion.ucl.ac.uk/spm/docs/development/compilation/windows Launch the Octave GUI from the MSYS2 environment. ```bash /mingw64/bin/octave --gui ``` -------------------------------- ### Install Octave for MSYS2 Source: https://www.fil.ion.ucl.ac.uk/spm/docs/development/compilation/windows Install the Octave package via pacman. ```bash pacman -S mingw64/mingw-w64-x86_64-octave ``` -------------------------------- ### Install build-essential Package Source: https://www.fil.ion.ucl.ac.uk/spm/docs/development/compilation/linux If you encounter 'cannot find -lstdc++' or 'math.h' errors, install the 'build-essential' package on Debian/Ubuntu systems. ```bash sudo apt install build-essential ``` -------------------------------- ### Load and Run Phantom Example Batch Script Source: https://www.fil.ion.ucl.ac.uk/spm/data/fieldmap/PhantomExample_readme.txt Execute the example batch script for the FieldMap toolbox at the Matlab command line. Ensure the 'pm_defaults_PhantomExample.m' file is correctly configured. ```matlab PhantomExample_fieldmap_batch.m ``` -------------------------------- ### Install libXp on Linux (yum) Source: https://www.fil.ion.ucl.ac.uk/spm/docs/installation/standalone Use yum to install the libXp package on your Linux distribution to resolve 'libXp.so.6' errors. ```bash yum install libXp.x86_64 ``` -------------------------------- ### Load Batch for Phantom Example Source: https://www.fil.ion.ucl.ac.uk/spm/data/fieldmap/PhantomExample_readme.txt Load a pre-saved batch configuration for the Phantom Example in SPM. This allows for easy execution of the FieldMap processing pipeline. ```matlab Batch->Load Batch to load PhantomExample_fieldmap_batch.mat and select run ``` -------------------------------- ### Install libstdc++5 Package Source: https://www.fil.ion.ucl.ac.uk/spm/docs/development/compilation/linux For older systems or specific 'lstdc++' issues, try installing the 'libstdc++5' package. Replace '5' with your system's version if necessary. ```bash sudo apt-get install libstdc++5 ``` -------------------------------- ### Compile libXp manually on Linux (Ubuntu/Debian) Source: https://www.fil.ion.ucl.ac.uk/spm/docs/installation/standalone Manually compile and install libXp if the package is not found on Ubuntu or Debian. This may require installing additional development packages. ```bash git clone [git://anongit.freedesktop.org/xorg/lib/libXp](git://anongit.freedesktop.org/xorg/lib/libXp) cd libXp ./autogen.sh ./configure make sudo make install ``` -------------------------------- ### Example Public Key Content Source: https://www.fil.ion.ucl.ac.uk/spm/docs/development/ssh_authentication The expected format of the public key string to be pasted into GitHub. ```text ssh-ed25519 AAAAC5NzaC1lZDI1NTE4AAAANI/iaJJ7eHWs+i2hxxQTX+xcalwd+QlhDSwgIkh3cvEc *your_email_here* ``` -------------------------------- ### Test SPM Installation Source: https://www.fil.ion.ucl.ac.uk/spm/docs/tutorials/beginners/installing_spm Run this command in the MATLAB command window after restarting MATLAB to verify that SPM has been installed correctly. A successful execution will launch the SPM GUI for fMRI analysis. ```matlab spm fmri ``` -------------------------------- ### Query SPM version and release Source: https://www.fil.ion.ucl.ac.uk/spm/docs/development/versioning Retrieve the version and release strings from the SPM installation. ```matlab [v, r] = spm('ver') ``` ```matlab spm('version') ``` -------------------------------- ### Display Condition Labels Source: https://www.fil.ion.ucl.ac.uk/spm/docs/tutorials/dcm/dcm_ir Example output showing the mapping of indices to condition labels. ```text ans = 'faces' 'scrambled' ``` -------------------------------- ### Configure MATLAB compilation environment Source: https://www.fil.ion.ucl.ac.uk/spm/docs/development/compilation/windows Set the MinGW location and run the MEX setup command within MATLAB. ```matlab setenv('MW_MINGW64_LOC', 'C:\msys64\mingw64') mex -setup % MEX configured to use 'MinGW64 Compiler (C)' for C language compilation. ``` -------------------------------- ### FieldMap Defaults Configuration Source: https://www.fil.ion.ucl.ac.uk/spm/data/fieldmap/SubjectExample_readme.txt Configuration file containing parameters specifically set for the Subject Example data. ```MATLAB pm_defaults_SubjectExample.m ``` -------------------------------- ### Get Help for MATLAB Command Source: https://www.fil.ion.ucl.ac.uk/spm/docs/courses/fmri_vbm/maths/linear_algebra Displays the help documentation for a specified MATLAB command or function, such as 'plot'. ```matlab help plot ``` -------------------------------- ### Octave Script for SPM12 Download, Configuration, and Installation Source: https://www.fil.ion.ucl.ac.uk/spm/docs/installation/octave This Octave script automates the download, patching, compilation of MEX files, and installation of SPM12. It also adds SPM12 to the function search path and starts SPM. ```octave %% Store current working directory cwd = pwd; %% Download SPM12 r7771 unzip ("https://github.com/spm/spm12/archive/r7771.zip", cwd); %% Patch SPM12 urlwrite ("https://raw.githubusercontent.com/spm/spm-octave/main/spm12_r7771.patch", "spm12_r7771.patch"); system ("patch -p3 -d spm12-r7771 < spm12_r7771.patch"); %% Compile MEX files cd (fullfile (cwd, "spm12-r7771", "src")); system ("make PLATFORM=octave"); system ("make PLATFORM=octave install"); %% Add SPM12 to the function search path addpath (fullfile (cwd, "spm12-r7771")); cd (cwd); %% Start SPM12 spm ``` -------------------------------- ### Format Commit Messages Source: https://www.fil.ion.ucl.ac.uk/spm/docs/development/git Example of the required commit message structure, starting with a prefix and including a detailed body. ```text Enhancement: replace this with that in such and such Longer description that might contain bullet points: * item 1 * item 2 ``` -------------------------------- ### View SSH Key Generation Output Source: https://www.fil.ion.ucl.ac.uk/spm/docs/development/ssh_authentication Example output showing the successful creation of the public and private key files. ```text Generating public/private ed25519 key pair. Enter file in which to save the key (/home/*your_user*/.ssh/id_ed25519): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/*your_user*/.ssh/id_ed25519 Your public key has been saved in /home/*your_user*/.ssh/id_ed25519.pub The key fingerprint is: SHA256:T3kB6rMhciPlSqcHp3SDmmoFu+ZDqs7IxFVcuj4JNeY *your_email* The key's randomart image is: +--[ED25519 256]--+ | . . | | . o . . | | . S . . | | .. * o. . . | | o* E. D o . | |..=oB.+. * . | | +=*.X . . | |**. *.o | |X= u.u | +----[SHA256]+----- ``` -------------------------------- ### Get M/EEG Object Information Source: https://www.fil.ion.ucl.ac.uk/spm/docs/tutorials/MEEG/multimodal/eeg Retrieve specific information about the M/EEG object 'D' using its methods. For example, D.ntrials returns the number of trials, D.conditions lists condition labels, and D.reject shows rejected trials. ```matlab D.ntrials ``` ```matlab D.conditions ``` ```matlab D.reject ``` ```matlab D.condlist ``` ```matlab D.chanlabels ``` ```matlab D.chantype ``` ```matlab D.size ``` ```matlab D.nchannels ``` ```matlab D.nsamples ``` ```matlab D.ntrials ``` -------------------------------- ### Check and Install SPM12 Updates Source: https://www.fil.ion.ucl.ac.uk/spm/software/spm12 Use the spm_update function to check for and install new SPM12 updates. The 'update' argument initiates the download and installation process. ```matlab >> spm_update A new version of SPM is available. ``` ```matlab >> spm_update update Download and install in progress... Success: xx files have been updated. ``` -------------------------------- ### Initialize SPM and Load Data Source: https://www.fil.ion.ucl.ac.uk/spm/docs/tutorials/opm/neuro1_aef Add the SPM path, initialize the environment, and create the SPM OPM object from BIDS-formatted files. ```matlab % Run spm (change path as appropriate) addpath('D:\GitHub\spm') spm eeg % Reference the meg and peripheral files S = []; S.category = 'meg'; S.description = 'meg'; S.type = '.lvm'; S.derivative = 0; S.BIDS = BIDS; meg_dir = spm_BIDS_file(S); S.description = 'positions'; S.type = '.tsv'; pos_dir = spm_BIDS_file(S); S.description = 'channels'; chan_dir = spm_BIDS_file(S); S.category = 'anat'; S.description = 'mri'; S.type = '.nii'; S.detailed = 0; anat_dir = spm_BIDS_file(S); % Load the raw data S = []; S.data = meg_dir.file; S.sMRI = anat_dir.file; S.channels = chan_dir.file; S.positions = pos_dir.file; S.lead = 0; % We will calculate leadfields later S.fs = 375; D = spm_opm_create(S) ``` -------------------------------- ### Automate File Selection in MATLAB Script Source: https://www.fil.ion.ucl.ac.uk/spm/docs/tutorials/MEEG/multi/preprocessing Example of using fullfile and sprintf to dynamically define input paths for multiple runs. ```matlab inputs{1, crun} = cellstr(fullfile(rawpth,'Sub15','MEEG',sprintf('run_%02d_sss.fif',crun))); inputs{2, crun} = cellstr(fullfile(rawpth,'Sub15','MEEG','Trials',sprintf('run_%02d_trldef.mat',crun))); inputs{3, crun} = cellstr(fullfile(rawpth,'Sub15','MEEG','bad_channels.mat')); ``` -------------------------------- ### Create Statistics Directory Source: https://www.fil.ion.ucl.ac.uk/spm/docs/tutorials/MEEG/multimodal Initial step to prepare a workspace for statistical output files. ```bash mkdir XYTstats ``` -------------------------------- ### Perform Initial CTF Unpacking Source: https://www.fil.ion.ucl.ac.uk/spm/docs/installation/standalone Execute the application with the 'quit' argument to unpack the CTF file, typically required when installing system-wide. ```bash ./run_spmxx.sh /usr/local/MATLAB/MATLAB_Runtime// quit ``` -------------------------------- ### Compile SPM MEX Files Source: https://www.fil.ion.ucl.ac.uk/spm/docs/development/compilation/linux Run these commands in the 'src' folder of your SPM installation to compile MEX files. Ensure you have a C/C++ compiler and 'make' installed. ```bash make distclean make && make install make external-distclean make external && make external-install ``` -------------------------------- ### Start SPM in MATLAB Source: https://www.fil.ion.ucl.ac.uk/spm/docs/tutorials/beginners/vbm/displaying_images Launch SPM from the MATLAB command line. Use 'spm' for the default interface or 'spm pet' for a PET-specific interface. ```matlab spm ``` ```matlab spm pet ``` -------------------------------- ### Run SPM Docker Container with GUI Source: https://www.fil.ion.ucl.ac.uk/spm/docs/installation/containers Use this command to start the SPM Docker container with graphical user interface support. Ensure X11 forwarding is correctly set up. ```bash xhost +local:docker docker run -ti --rm -e DISPLAY=$DISPLAY -v /tmp:/tmp -v /tmp/.X11-unix:/tmp/.X11-unix ghcr.io/spm/spm-docker:docker-matlab-latest fmri ``` -------------------------------- ### Install SPM12 Updates on Unix Systems Source: https://www.fil.ion.ucl.ac.uk/spm/software/spm12 Command line instructions for installing SPM12 updates on Unix-based systems (Linux, macOS) using unzip. Ensure newer files overwrite existing ones. ```bash unzip spm12.zip unzip -o spm12_updates_rxxxx.zip -d spm12 ``` -------------------------------- ### Troubleshoot SPM Startup Crash Source: https://www.fil.ion.ucl.ac.uk/spm/docs/installation/matlab Example error output from a segmentation fault and the command to disable the HTML browser to fix it. ```text BadWindow (invalid Window parameter) serial 20133 error_code 3 request_code 20 minor_code 0 Pango-CRITICAL **: pango_font_description_from_string: assertion 'str != NULL' failed GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed GLib-GObject-CRITICAL **: g_type_register_dynamic: assertion 'parent_type > 0' failed ``` ```matlab setenv('SPM_HTML_BROWSER','0') ``` -------------------------------- ### GET /events Source: https://www.fil.ion.ucl.ac.uk/spm/docs/reference/MEEG/eeg_preprocessing Retrieves event information stored with trials. ```APIDOC ## GET /events ### Description Returns a structure array of events associated with trials. ### Response #### Success Response (200) - **type** (string) - Event type - **value** (number/string) - Event value - **time** (number) - Time in seconds - **duration** (number) - Optional duration in seconds ``` -------------------------------- ### Function Usage and Plotting Source: https://www.fil.ion.ucl.ac.uk/spm/docs/tutorials/beginners/control_flow Example of calling a built-in function and plotting the results. ```MATLAB x = 0:0.01:2*pi; y = sin(x); plot(x,y) figure(gcf) ``` -------------------------------- ### Set up DCM Analysis Source: https://www.fil.ion.ucl.ac.uk/spm/download/data/attention/README_GLM_DCM.txt Initiates the Dynamic Causal Modelling (DCM) analysis setup. Requires specifying the SPM.mat file, VOIs, and connections. ```matlab Press DCM Specify or review [specify] Select the SPM.mat file you created in README_GLM Name for DCM_???.mat [VisFroPar] Select all VOIs in order VOI_V1_1, VOI_V5_1, VOI_PPC_1, VOI_PFC_1 Include Photic [Yes] Incluse Motion [Yes] Include Attention [Yes] Make the following intrinsic connections V1 to V5, V5 to V1, V5 to PPC, PPC to V5, PPC to PFC and PFC to PPC ie. a hierarchy with bidirectional connections Just connect Photic to V2 Connect Motion to modulate the bottom-up connection from V1 to V5 Connect Attention to modulate the top-down connections from PFC to PPC and from PFC to PPC. ``` -------------------------------- ### Make SPM Path Permanent (Local Installation) Source: https://www.fil.ion.ucl.ac.uk/spm/docs/tutorials/beginners/installing_spm This code snippet creates or appends to the MATLAB startup.m file to permanently add the SPM directory to the path. Ensure you replace 'yourusername' with your actual username and adjust the path if SPM was installed elsewhere. Note the double backslashes required in the fprintf function. ```matlab fid = fopen('C:\Users\yourusername\Documents\MATLAB\startup.m','w'); fprintf(fid, 'addpath(''C:\Users\yourusername\Documents\MATLAB'');'); fclose(fid); ```