I created a function in_timefreq_fieldtrip.mat, which converts the fieldtrip struct data (powspctrm, time, freq, label) into a DataMat structure (generated by db_add('timefreqmat').
The function in_timefreq_fieldtrip should not copy the files into the database, it should simply convert the structure, therefore it should not call db_add(). But I guess you meant db_template('timefreqmat').
It seems to me that doing a function like import_matrix.m is not necessary because in the function in_timefreq_fieldtrip.mat I have all the elements in order to be able to create a file compatible with brainstorm.
Not necessary for you, but necessary for the other people who would like to use your code
The goal of this function would be only to call the conversion function and save it into the database.
However, I didn't do any code to create a channel.mat file and I don't know how to save the file in the database with db_add.
To create a default channel file, you can use something like this:
Or you can consider that it is not the job of this function to create a channel file... One option could be to load a piece of recordings of the initial recordings (which creates a channel file), and then import the TF file using this existing channel file.
Does this help?