Array indices must be positive integers or logical values. - specific to EEG data

6 ビュー (過去 30 日間)
I am trying to create spectrograms for specific brain areas, each brain area contains several electrodes (SEEG). This specific area (left_cingulate) contains 7 electrodes, extracted as arrays. Some of the values in the arrays are negative values, which is normal for EEG data. The error comes with the y=fft(data); line in the code. Error: Array indices must be positive integers or logical values. I have the signal processing toolbox installed.
clc
load data_left_cing.mat;% loading data
dt=0.0256
Fs=512;%sampling frequency
T = 1/Fs;% sampling period
TimeResolution=0.0256;
fft = 2^nextpow2(57001);
% [N]=size(data);%obtain size of data
t = (0:T-1)/Fs;%generates time vector
y=fft(data);% fft of data -------------------------------------->>> error
freq=(1:N)*Fs/N;%frequency vector
%SPECTROGRAM of channels
[S1,F,T] = spectrogram(data(:,7),window=hann,noverlap=50,Fs=512);
S1=abs(S1);
h3=figure;
mesh(T,F,S1);
xlabel('Time (s)','FontSize',14);
ylabel('Frequency (Hz)','FontSize',14);
zlabel('S1','FontSize',14);
h4=figure;
contour(T,F,S1);
xlabel('Time (sec)');
ylabel('Frequency (Hz)');
title('left cingulate');
Any help would be greatly appreciated, I'm not sure where I'm going wrong.

採用された回答

Walter Roberson
Walter Roberson 2023 年 2 月 14 日
fft = 2^nextpow2(57001);
Before that line, fft is the name of a MATLAB function.
After that line is executed, fft in your workspace is now the name of a variable.
y=fft(data);% fft of data -------------------------------------->>> error
and so that beomes a request to index the variable, rather than to call the fft routine.
Moral of the story: avoid naming variables the same as MATLAB routines that in common use. Especially avoid naming a variable sum -- people get caught with that one a lot.
  5 件のコメント
Walter Roberson
Walter Roberson 2023 年 2 月 14 日
You probably did not
clear fft
so it was probably still in your workspace.
Antoinette Burger
Antoinette Burger 2023 年 2 月 15 日
Thank you!

サインインしてコメントする。

その他の回答 (1 件)

Torsten
Torsten 2023 年 2 月 14 日
移動済み: Torsten 2023 年 2 月 14 日
Rename this variable - it conflicts with MATLAB's "fft" function.
fft = 2^nextpow2(57001);

カテゴリ

Help Center および File ExchangeEEG/MEG/ECoG についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by