I am getting this error and I don't know why.
Index in position 1 is invalid. Array indices must be positive integers or logical values.
This is the line I am getting it for:
plot(EEG.times,squeeze(EEG.data(channel_index,:,:)),'y')
I attached the data set that can be loaded to see what is going on.
I tried to attach the data file, but it is too large; even when compressed. The data file is sampleEEGdata.mat and can be found in this code downloaded from this link http://mikexcohen.com/book/AnalyzingNeuralTimeSeriesData_MatlabCode.zip

 Respuesta aceptada

Star Strider
Star Strider el 16 de Jun. de 2021
In MATLAB, indices must be integers greater than 0.
This illustrates a way to get some of the data and plot it —
Uz = unzip('http://mikexcohen.com/book/AnalyzingNeuralTimeSeriesData_MatlabCode.zip')
Uz = 1×57 cell array
{'code/accumbens_eeg.mat'} {'code/amsterdam.bmp'} {'code/armorf.m'} {'code/chapter02.m'} {'code/chapter04_datafile.txt'} {'code/chapter04_excel_data.xls'} {'code/chapter04_headache_data.txt'} {'code/chapter04a.m'} {'code/chapter04b.m'} {'code/chapter04c.m'} {'code/chapter05.m'} {'code/chapter06.m'} {'code/chapter09.m'} {'code/chapter10.m'} {'code/chapter11.m'} {'code/chapter12.m'} {'code/chapter13.m'} {'code/chapter14.m'} {'code/chapter15.m'} {'code/chapter16.m'} {'code/chapter17.m'} {'code/chapter18.m'} {'code/chapter19.m'} {'code/chapter20.m'} {'code/chapter22.m'} {'code/chapter23.m'} {'code/chapter25.m'} {'code/chapter26.m'} {'code/chapter27.m'} {'code/chapter28.m'} {'code/chapter29.m'} {'code/chapter30.m'} {'code/chapter31.m'} {'code/chapter33.m'} {'code/chapter34.m'} {'code/cover_art.m'} {'code/data_output_SPSS_format.txt'} {'code/data_written_from_matlab.txt'} {'code/data2psiX.m'} {'code/emdx.m'} {'code/entropyx.m'} {'code/erpviewerx.fig'} {'code/erpviewerx.m'} {'code/fdr.m'} {'code/figure34_3_data.mat'} {'code/frequency_sliding_and_median_filter.m'} {'code/interpolate_nola.m'} {'code/interpolate_perrinX.m'} {'code/laplacian_nola.m'} {'code/laplacian_perrinX.m'} {'code/mutualinformationx.m'} {'code/my_matlab_variables.mat'} {'code/pathlength.m'} {'code/sampleEEGdata.mat'} {'code/solutions2exercises.pdf'} {'code/tfviewerx.fig'} {'code/tfviewerx.m'}
% n = strcmp(Uz{:},'sampleEEGdata')
D1 = load(Uz{54});
EEG = D1.EEG
EEG = struct with fields:
setname: 'EEG sample dataset' filename: '' filepath: '' subject: '' group: '' condition: '' session: [] comments: [4×63 char] nbchan: 64 trials: 99 pnts: 640 srate: 256 xmin: -1 xmax: 1.4961 times: [1×640 double] data: [64×640×99 single] icaact: [] icawinv: [] icasphere: [] icaweights: [] icachansind: [] chanlocs: [1×64 struct] urchanlocs: [] chaninfo: [1×1 struct] ref: [-67 -68] event: [1×311 struct] urevent: [1×3009 struct] eventdescription: {'' '' '' '' ''} epoch: [1×99 struct] epochdescription: {} reject: [1×1 struct] stats: [1×1 struct] specdata: [] specicaact: [] splinefile: '' icasplinefile: [] dipfit: [] history: '↵pop_eegplot( EEG, 1, 1, 1);↵EEG.setname='TheNewWave';↵EEG = pop_rejepoch( EEG, find(EEG.reject.rejglobal), 0);↵EEG = eeg_checkset( EEG );' saved: 'no' etc: [1×1 struct] spedata: []
times = EEG.times;
data = EEG.data;
chans = EEG.chanlocs;
channel_index = 1:4;
figure
for k = 1:numel(channel_index)
subplot(2,2,k)
plot(EEG.times,squeeze(EEG.data(channel_index(k),:,:)),'b')
title(sprintf('Channel %s',EEG.chanlocs(k).labels))
xlabel('Time')
ylabel('Amplitude')
grid
end
sgtitle('First Four Channels')
.

2 comentarios

Ryan Griffith
Ryan Griffith el 16 de Jun. de 2021
Thanks!
Star Strider
Star Strider el 16 de Jun. de 2021
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 16 de Jun. de 2021

Comentada:

el 16 de Jun. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by