Find exceeds array ERROR
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Neda Deljavan
am 23 Jan. 2023
Bearbeitet: Les Beckham
am 23 Jan. 2023
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 Kommentare
Akzeptierte Antwort
Les Beckham
am 23 Jan. 2023
Bearbeitet: Les Beckham
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!