Find exceeds array ERROR

1 次查看(过去 30 天)
Hello everybody,
I came across with this error in my code which is below, What should I do to fix it?
Code:
%% step15: Phase Locking Value (PLV)
% How well waves' phases are locked in a phase synchrony. The main idea is
% to take the phases of waveforms by taking into account the real part of the Hilbert Transform of signals.
% Then applying the equation.
%Here we take phases for subject one. Variable " phis " is then the phases of 91 signals of subject one.
sujeto = 1;
phis = angle(hilbert(subs_cd1_al(:,:,sujeto)'));
% Now computing PLV over phases "phis" of subject one.
pairs = nchoosek(1:4,1); % all combinations of 4 channels
plv = zeros(4,4);
for pr = 1 : length(pairs)
plv(pairs(pr,1), pairs(pr,2)) = abs(sum(exp(1i* ( phis(:,pairs(pr,1)) - phis(:,pairs(pr,2)) ))))/length(phis);
end
plv = plv + plv'; % we take its transpose to create the connectivity matrix
figure
imagesc(plv);colorbar;
axis square; colorbar
title('PLV')
Error:
Index in position 2 exceeds array bounds (must not exceed 1).
Error in NEW1 (line 296)
plv(pairs(pr,1), pairs(pr,2)) = abs(sum(exp(1i* ( phis(:,pairs(pr,1)) - phis(:,pairs(pr,2)) ))))/length(phis);

采纳的回答

Les Beckham
Les Beckham 2023-1-23
编辑:Les Beckham 2023-1-23
One obvious problem with this code is where you try to access pairs(pr,2) but pairs is a one dimensional (4x1) vector. Perhaps you need to revise the definition of pairs?
pairs = nchoosek(1:4,1)
pairs = 4×1
1 2 3 4
Maybe you meant this?
pairs = nchoosek(1:4,2)
pairs = 6×2
1 2 1 3 1 4 2 3 2 4 3 4

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by