Find exceeds array ERROR

5 ビュー (過去 30 日間)
Neda Deljavan
Neda Deljavan 2023 年 1 月 23 日
編集済み: Les Beckham 2023 年 1 月 23 日
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 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by