Writing a script for peak latency

Dear Francois

I need to find the latency of peak amplitude in each trial separately. I think I should write a matlab script but there is a problem. in some of my trials I have choosed some channels as bad ones. but these channels are quantified in matlab matrix and they will be included when I run my script.
is there any way to exclude them quickly?
or can I write my script in the brainstorm program?

Best
Shadi

Hi Shady,

You can get the list of bad channels from the ChannelFlag field.
iBad = find(DataMat.ChannelFlag == -1);
iGood = find(DataMat.ChannelFlag == 1);

Keep only the good signals:
DataMat.F(iGood,:);

More information on the file structure for MEG/EEG recordings:
http://neuroimage.usc.edu/brainstorm/Tutorials/Epoching#On_the_hard_drive

Cheers,
Francois

thanks for your reply.
now I have finished my script. I want to see if it is possible to run it in brainstorm. I read the tutorial page titled “write your own script” but unfortunately I couldn’t insert it in pipelines even after saving it in brainstorm path. it seems that it does not know variables such as channelflag.
is it possible to run it in brainstorm or maybe writing a new command?

Best
Shadi

Hi Shadi,
Start from an existing process, as described here:
http://neuroimage.usc.edu/brainstorm/Tutorials/TutUserProcess#Create_your_own_process
Then let me know precisely the errors you are getting.
Francois

Dear Francois
I read the tutorial again and I changed one of the function structure but it didn’t appear on list.
It seems to be easier to work by runing the matlab command in the preprocess tab. but still I have a problem. the script is working when I use it in editor menu while the variables are open in workspace but it is not responding to my variables when I run it in brainstorm. the error message is :"undefined function or method "ChannelFlag’ for input arguments of type ‘double’.
also when I try to run the Function in Matlab I have this problem.

would you guide me plz?
Shadi

Hi Shadi,
When using the process “Pre-process > Run Matlab command”, you only have access to two variables: Data and TimeVector.
If you don’t want to go through the necessary steps to write a process, the easier for you is maybe simply to read the file from a script with Matlab “load” function.
Francois