Trying to randomly permute a time series, error with time point
1 次查看(过去 30 天)
显示 更早的评论
Dear Matlab,
I have an EEG signal, which I ran through wavelet convolution to produce a 3D matrix of time-frequency values, that is:
1 X 68(frex) X 4000(time points)
GOAL: Now the next step is to randomly slice the tf matrix and reoder time zero (and effectively reorder the map, to 'shuffle' it), by running the tf map/variable through 1000 rounds of permutations.
(see code below here, and attached tf mat file to run it):
% PERMING power values
num_iterations = 1000;
permuted_results = zeros(num_iterations,length(frex),length(times2));%zeros(1,num_iterations);
for ni=1:num_iterations
% randomly resort power values
cutpoint = times2(randi(numel(times2)));
permuted_results(ni,:,:,:) = tf(:,:,[ cutpoint:end 1:cutpoint-1 ]);
end
PROBLEM: when I run the for loop, I get this error:
Index in position 3 is invalid. Array indices must be positive integers or logical values.
Is it because the time series, which goes from -1000 to 3000 milliseconds, is it the negative values in there?
Thanks very much in advance for any help/guidance!
Best,
Joanne
2 个评论
Dyuman Joshi
2023-5-2
"Is it because the time series, which goes from -1000 to 3000 milliseconds, is it the negative values in there?"
Yes.
load('TFsample.mat')% PERMING power values
num_iterations = 1000;
permuted_results = zeros(num_iterations,length(frex),length(times2));%zeros(1,num_iterations);
for ni=1:num_iterations
% randomly resort power values
cutpoint = times2(randi(numel(times2)))
permuted_results(ni,:,:,:) = tf(:,:,[ cutpoint:end 1:cutpoint-1 ]);
end
采纳的回答
Constantino Carlos Reyes-Aldasoro
2023-5-2
A=[1 2 3 4 5 6 7]
A(1:3)
A(-1:2)
Yes, Matlab needs the index of the position starting from 1, so if you use negative numbers there will be an error.
6 个评论
Dyuman Joshi
2023-5-3
"How to fix?"
It depends on what you want to do.
You can either use abs()
cutpoint = abs(times2(randi(numel(times2))))
or add 1001 to times2 (as suggested above) to adjust its values, which will change to 1 to 4001 (milliseconds).
times2 = times2 + 10001;
cutpoint = times(randi(numel(times2)))
%similar to the above two lines
cutpoint = randi(numel(times2))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 EEG/MEG/ECoG 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!