Import several structures from one matrix .mat file

Hello BST users and developers,

I'm currently struggling with a specific issue when I try to import data.

My data have particular structure: .mat files are matrices which contain Fieldtrip structures per conditions. In other words, one .mat file per subject, and in each .mat file, there are 27 Fieldtrip structures.

The purpose here is to import for each subject ALL the conditions, i.e., all the Fieldtrip structures in .mat files.
However, when I try to import in BST my .mat files, it imports the information for the first Fieldtrip structure only.

Do you know if it's possible to manage this problem in BST interface?

Thank you

No, Brainstorm does not support importing files with multiple FieldTrip structures, only multiple trials from a single structure.
The easiest solution is probably to split the files in multiple files, one for each FieldTrip structure.
This can be done with a simple Matlab with a few lines of code: load the file and loop to save the various structures. Something like the script below (which I can't more precise than this because I don't know how the multiple structures are grouped in the file):

function OutFiles = SplitFile(InFile)
    OutFiles = {};
    AllMat = load(InFile);
    for i = 1:length(...)
        FtMat = AllMat...;
        OutFiles{i} = [InFile(end-3:end), '-', sprintf('%03d',i), '.mat'];
        save(OutFiles{i}, '-struct', 'FtMat');
    end
end

Thank you for your answer. I'm currently struggling with this code. Indeed, when i try to implement it, I have this kind of error:

>> OutFiles{i}

ans =

  2×2 cell array

    {'.mat'}    {["_" ]}
    {'027' }    {'.mat'}

>> save(OutFiles{i}, '-struct', 'AllMat')
Error using save
Must be a string scalar or character vector.

I'm not sure I fully understand this process, would you like explain the 'save' part more further please?

Thank you

It was just an example to give general directions, not actual code to be executed as is.
You need to have some experience with Matlab programming in order to write your own Matlab scripts.
I won't be able to provide anything more precise because you didn't explain what was in your files.

From the error you get, I can understand two things:

  • Infile must be an array of char: not a string, not a cell array.
  • I selected the wrong part of the string when defining OutFiles{i}, replace it with something like:
    OutFiles{i} = [InFile(1:end-4), '-', sprintf('%03d',i), '.mat'];

Thank you for your help! I solved this issue