Find exceeds array ERROR
1 view (last 30 days)
Show older comments
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);
0 Comments
Accepted Answer
Les Beckham
on 23 Jan 2023
Edited: Les Beckham
on 23 Jan 2023
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)
Maybe you meant this?
pairs = nchoosek(1:4,2)
0 Comments
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!