Error in sort function when grouping events

2 views (last 30 days)
Hi there,
I've got a piece of code, which I'm using to select and sort (average) some electroencephalography events. Here is my code:
fname=dir('*_TF_cue_pru_rej_conditions_TF.mat'); % select all participant files
fname={fname.name};
% do a grand average of the data for each condition, per person
for k=1:length(fname),
load(fname{k})
cfg.trials =L1_NS_data_rej; %Language 1 non-switch events
G_L1_NS{k}=ft_redefinetrial(cfg,data_TF);
cfg.trials =L1_S_data_rej; %Language 1 switch events
G_L1_S{k}=ft_redefinetrial(cfg,data_TF);
cfg.trials =L2_NS_data_rej; %Language 2 non-switch events
G_L2_NS{k}=ft_redefinetrial(cfg,data_TF);
cfg.trials =L2_S_data_rej; %Language 2 switch events
G_L2_S{k}=ft_redefinetrial(cfg,data_TF);
end
The events are 4 types and are already grouped into 4 different substructures of my data file (as commented above). My data file countains the whole data (data_TF) and 4 other structures named L1_NS_data_rej, L1_S_data_rej, L2_NS_data_rej and L2_S_data_rej. However, when I try running it, I get the following error in the sort function:
Error using sort
Check for missing argument or incorrect argument data type in call to function 'sort'.
Error in ft_selectdata>getselection_rpt (line 1179)
rptindx = unique(sort(rptindx));
Error in ft_selectdata (line 291)
[selrpt{i}, dum, rptdim{i}, selrpttap{i}] = getselection_rpt(cfg, varargin{i}, dimord{j});
Error in ft_redefinetrial (line 129)
data = ft_selectdata(tmpcfg, data);
It used to work perfectly on the same datafiles I'm attempting to use it now. I've checked my data files and they're not empty, all the events are there and named appropriately, etc. I'm attaching a link to two of my files, so that one could run the code: https://we.tl/t-pjfMr2hwSf MatLab version: MATLAB Version: 9.9.0.1570001 (R2020b) Update 4 (Windows 10). Fieldtrip versions: fieldtrip-lite-20210310 and fieldtrip-lite-20210411. Could you please help me resolve where the problem might be? Thank you!
  4 Comments
Zlatomira Ilchovska
Zlatomira Ilchovska on 9 Jun 2021
@dpb Hi there! All the code is added in my post. It's the example two files that are attached as an external link.
@Walter Roberson Hi there! I tried doing that but I still get the same error. I'm not sure that's the problem.
dpb
dpb on 9 Jun 2021
Only the top level code; there's no code that has any reference to sort there; what are we to try to do?
And, attach the data as .mat file here as well; nobody is going to an external site.
If you expect somebody to try to actually debug what is going on, need a sample case that can run in its entirety without having to make it themselves by bits and pieces scattered all around.

Sign in to comment.

Answers (2)

Jan
Jan on 9 Jun 2021
Use the debugger:
dbstop if error
Afterwards start your code again. When Matlab stops at the error, what is the contents of rptindx?

Zlatomira Ilchovska
Zlatomira Ilchovska on 9 Jun 2021
Edited: Zlatomira Ilchovska on 10 Jun 2021
I've resolved it and it's quite a trivial issue that I had, with inappropriate use of ft_redefinetrial (where sort command sits). The issue is that the function expects (in my case) a vector or a number of trials indices I'd like to keep/offset/etc. and I was passing onto it the selected trials with the data in them. In other words, ft_redefinetrial was just not needed. I've resolved it by simply changing the above code into:
fname=dir('*_TF_cue_pru_rej_conditions_TF.mat'); % select all participant files
fname={fname.name};
% do a grand average of the data for each condition, per person
for k=1:length(fname),
data = load(fname{k})
G_L1_NS{k}=data.L1_NS_data_rej; %Language 1 non-switch events
G_L1_S{k}=data.L1_S_data_rej; %Language 1 switch events
G_L2_NS{k}=data.L2_NS_data_rej; %Language 2 non-switch events
G_L2_S{k}=data.L2_S_data_rej; %Language 2 switch events
end
And the data was on an external link because, expectedly, it was way too large to be attached.

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!