<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Hi Selena,
<div class=""><br class="">
</div>
<div class="">I don’t understand why you think you need to call ft_definetrial when using data that seems to be in  a matlab mat-file. I would assume that the P24DR_rawdata.mat file contains already a fieldtrip compatible data structure with one or more ’trials’
 in the data.trial field.</div>
<div class=""><br class="">
</div>
<div class="">Also, if you call ft_preprocessing with already a data structure in the input (which you seem to do), the cfg.trl which may have been computed (either correctly or incorrectly) will not be applied to the input data object. The cfg.trl field will
 only apply if you are reading (raw) data from disk directly.</div>
<div class=""><br class="">
</div>
<div class="">If you want to chop up a long continuous data recording that you have already loaded into memory, you should not use ft_definetrial, but rather you should use ft_redefinetrial.</div>
<div class=""><br class="">
</div>
<div class="">Also, of note, if you want to compute a meaningful connectivity using FieldTrip, you will need more than a single trial to compute it, because the trial dimension will be used as the unit-of-observation for the connectivity estimate.</div>
<div class=""><br class="">
</div>
<div class="">Best wishes,</div>
<div class="">Jan-Mathijs</div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 9 Aug 2023, at 20:24, Selena Zhang via fieldtrip <<a href="mailto:fieldtrip@science.ru.nl" class="">fieldtrip@science.ru.nl</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">Hello all,
<div class=""><br class="">
</div>
<div class="">I'm new to FieldTrip so I would appreciate any help I can get.</div>
<div class="">I'm trying to plot the connectivity of many different channels with the direct transfer function.</div>
<div class=""><br class="">
</div>
<div class="">My problem right now is that once I get the output of ft_freqanalysis, the time scale just runs through all of the trials instead of just the length of one trial. I did ft_definetrial, and it properly defined all 54 trials, although it didn't
 detect any events, so I'm not sure what the problem could be.</div>
<div class=""><br class="">
</div>
<div class="">Here is my code:<br class="">
<br class="">
<div class="gmail-rtcContent" style="padding:30px">
<div class="gmail-lineNode" style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">
<span style="white-space:pre" class="">cfg = [];</span></div>
<div class="gmail-lineNode" style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">
<span style="white-space:pre" class="">cfg.trialfun = <span style="color:rgb(167,9,245)" class="">
'ft_trialfun_general'</span>;</span></div>
<div class="gmail-lineNode" style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">
<span style="white-space:pre" class="">cfg.eventtype = 1;</span></div>
<div class="gmail-lineNode" style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">
<span style="white-space:pre" class="">cfg.trialdfef.eventvalue = 1; <span style="color:rgb(0,128,19)" class="">
% limits to only valid and Go trials (in case of GNG)</span></span></div>
<div class="gmail-lineNode" style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">
<span style="white-space:pre" class="">cfg.trialdef.prestimulus = min2/fs;</span></div>
<div class="gmail-lineNode" style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">
<span style="white-space:pre" class="">cfg.trialdef.poststimulus = min3/fs;</span></div>
<div class="gmail-lineNode" style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">
<span style="white-space:pre" class="">cfg.dataset = <span style="color:rgb(167,9,245)" class="">
'Users/selenazhang/Documents/MATLAB/blxlab/data/Data P024 Direct Reach/connectivity/P24DR_rawdata.mat'</span>;</span></div>
<div class="gmail-lineNode" style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">
<span style="white-space:pre" class="">cfg.trialdef.ntrials = length(trials);</span></div>
<div class="gmail-lineNode" style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">
<span style="white-space:pre" class="">cfg.trialdef.length = (min2+min3+1)/fs;</span></div>
<div class="gmail-lineNode" style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">
</div>
<div class="gmail-lineNode" style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">
</div>
<div class="gmail-lineNode" style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">
<span style="white-space:pre" class="">[cfg] = ft_definetrial(cfg);</span></div>
<div class="gmail-lineNode" style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">
<span style="white-space:pre" class=""><br class="">
</span></div>
<div class="gmail-lineNode" style="font-size:13px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">
<div class="gmail-rtcContent" style="padding:30px">
<div class="gmail-lineNode"></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">cfg.channel = <span style="color:rgb(167,9,245)" class="">
'all'</span>;</span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">cfg.continuous =
<span style="color:rgb(167,9,245)" class="">'yes'</span>;</span></div>
<div class="gmail-lineNode"></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">[preprocess_data] = ft_preprocessing(cfg, rawdata);</span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class=""><br class="">
</span></div>
<div class="gmail-lineNode">
<div class="gmail-rtcContent" style="padding:30px">
<div class="gmail-lineNode"><span style="white-space:pre" class="">cfg = [];</span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">cfg.method = <span style="color:rgb(167,9,245)" class="">
'mtmconvol'</span>; <span style="color:rgb(0,128,19)" class="">% multi taper time-freq analysis</span></span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">cfg.output = <span style="color:rgb(167,9,245)" class="">
'powandcsd'</span>; <span style="color:rgb(0,128,19)" class="">% power and cross spectrum</span></span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">cfg.channel = <span style="color:rgb(167,9,245)" class="">
'all'</span>;</span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">cfg.trials = <span style="color:rgb(167,9,245)" class="">
'all'</span>;</span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">cfg.pad = 3; <span style="color:rgb(0,128,19)" class="">
% adding padding allows for desired foi </span></span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">cfg.channelcmb = {<span style="color:rgb(167,9,245)" class="">'all'
</span><span style="color:rgb(167,9,245)" class="">'all'</span>}; <span style="color:rgb(0,128,19)" class="">
% which channels to cross spectrum</span></span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">cfg.taper = <span style="color:rgb(167,9,245)" class="">
'hanning'</span>;</span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">cfg.foi = 13:1:30;
<span style="color:rgb(0,128,19)" class="">% frequency of interests [13 30] Hz</span></span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">cfg.t_ftimwin = ones(1,length(cfg.foi))*.4;
<span style="color:rgb(0,128,19)" class="">% moving window in seconds as a 1xnumfoi vector</span></span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">cfg.toi = <span style="color:rgb(167,9,245)" class="">
'99%'</span>; <span style="color:rgb(0,128,19)" class="">% overlap of each window, like step size</span></span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">cfg.avgovertrials =
<span style="color:rgb(167,9,245)" class="">'yes'</span>;</span></div>
<div class="gmail-lineNode"></div>
<div class="gmail-lineNode"></div>
<div class="gmail-lineNode"><span style="white-space:pre" class="">[freqanalysis_data] = ft_freqanalysis(cfg, preprocess_data);</span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class=""><br class="">
</span></div>
<div class="gmail-lineNode"><span style="white-space:pre" class=""><br class="">
</span></div>
<div class="gmail-lineNode">Any idea of what could be wrong? (rawdata is structured the way ft_datatyperaw describes) Thanks!</div>
<div class="gmail-lineNode"><br class="">
</div>
<div class="gmail-lineNode">Best,</div>
<div class="gmail-lineNode">Selena</div>
</div>
</div>
<div class="gmail-lineNode"><span style="white-space:pre" class=""></span></div>
<div class="gmail-lineNode"></div>
</div>
</div>
</div>
</div>
</div>
_______________________________________________<br class="">
fieldtrip mailing list<br class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br class="">
<a href="https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!7fpApjTY9lQ9-UFzRMOYK_kBRm_dRlAjJl0WV3nKrAYQGFFcXObuDxdPEe6wB8prGyCNIAemmHD3OeScmSzQCFSAGWo_o7NhewiuvA$">https://doi.org/10.1371/journal.pcbi.1002202</a><br class="">
</div>
</blockquote>
</div>
<br class="">
</body>
</html>