- You're using a lot of comments. This is very good. You should keep doing this. In a month you may no longer understand your variables or what you're doing and why.
- You're using a script. This is fine for debugging, but not for serious work. Use functions instead. That provides a stable interface that you can document and reuse. Follow the Onramp course and/or read the documentation for advice.
- You're using length. That probably doesn't do what you think it does. I have yet to find a situation where length was the correct choice. If you want to know the number of elements you should use numel, if you want to know the number of rows/columns/pages/volumes/etc you should use size (specifying the dimension).
- You have several numbered variables. Consider using an array instead. You're hiding a variable in a name, making it hard to do the same thing for all variable, since you need to copy-paste everything.
- You're using + to concatenate text. This is fine for string inputs, but not char. However, you don't seem to make sure to test/convert. You might want to look into sprintf to compose text based on inputs.
Undefined function 'hamming' for input arguments of type double
8 views (last 30 days)
Show older comments
I have been trying to obtain statistics of a resting EEG with EEGSTATS plugin. When I try to run it manually I get the error "Undefined function 'hamming' for input arguments of type double". I tried creating the hamming function but then it list another error relating to slag ( defined inside the hamming function:
function: w = hamming(L)
end
I have also tried to do it automatically with the following code, but in the last two lines it lists: Arrays have incompatible sizes for this operation.
Does anyone know a possible solution?
** The problem is in the last section, the rest of the code runs without problems.
% Análisis de potencia espectral
name='PAC01_5min.previos_ICA_refA2done_filt_epochs'+'eegstats';
pop_eegstats(EEG, 'thetarange',[4 8],'alpharange',[8 12], 'otherranges', [1 4; 12 30; 30 50], 'averagepower', 'off', 'channels', (11):(63),'csvfile', 'PAC01_eegstats', 'iaf', 'off' );
clear
clc
eeglab
%% A configurar según sujeto
ruta='C:\Users\rebec\OneDrive\Escritorio\DATOS-EEG\PACIENTES\';
sujeto="PAC01";
set_sufix=".set";
%% Cargar archivo vhdr
EEG.etc.eeglabvers = '2023.0'; % this tracks which version of EEGLAB is being used, you may ignore it
EEG = pop_loadbv(ruta, sujeto+".vhdr", [1 300000]); %incluyo el rango de Interval de [1 300000] para incluir los 300ms iniciales con los ojos cerrados
EEG=pop_chanedit(EEG, []); %%se debe seleccionar el fichero MNI coordinate file for BEM dipfit model. En concreto, el plugins\dipfit\standard_BEM\elec\standard_1005.elc
ORG=EEG;% Guardo copia para poder obtener los índices de los canales originales (independientemente de si se han eliminado o no)
%% Eliminar canales que a priori sabemos que son ruidosos porque en el registro no funcionaban identificados mediante inspección visual MR
badchans=[42,63]; % Canales para cada sujeto: C03: [27]; C04: [40]; C05:[22 34 40]; C06, 7, 8:[40]; PAC01: [VEOGn,42,63], PAC02: [32]; PAC03 [11,15,27,33,37,47,51,62] PAC04: [42]; PAC05 [57],PAC06: [57]; PAC07: ningún electrodo ; PAC08 [42]; PAC09: [40]; PAC10: [40];
chansInterpolar=zeros(1, length(badchans));
i=0
for n=1:length(badchans)
if (badchans(n)>=47 && badchans(n)<=53) || (badchans(n)>=55 && badchans(n)<=61) || (badchans(n)>=21 && badchans(n)<=27) % Si el canal eliminado es uno de los electrodos de la linea central, lo interpolamos
chansInterpolar(n) = badchans(n);
i=i+1;
end
end
chansInterpolar=trimdata(chansInterpolar, i);
EEG = pop_select(EEG, 'rmchannel', badchans); % para c05 pero cambiar para cada registro los valores dentro de [] tras inspeccion visual
EEG=pop_chanedit(EEG, []);
%% Interpolar los canales eliminados MR
if length(chansInterpolar)>0
EEG = eeg_interp(EEG, ORG.chanlocs(chansInterpolar), 'spherical', [EEG.xmin EEG.xmax]); %%el canal interpolado se introduce en la posicion 63 así que hay que verificar en cada registro EEG.chanlocs para calcular a posteriori los parámetros qEEG
EEG=pop_chanedit(EEG, []); %%lo añado solo para comprobar que se han interpolado los canales que se han indicado
eegplot();
end
%% Aplicar filtro notch a 50Hz
EEG = pop_eegfiltnew(EEG, 'locutoff',49,'hicutoff',51,'revfilt',1,'plotfreqz',1);
EEG=pop_chanedit(EEG, []); %quitar localizaciones A1
%% Eliminar canales cuyo espectro se desvíe de un umbral, por defecto 5
try
chHEOGn=find(strcmp({EEG.chanlocs.labels}, 'HEOGn'));
chVEOGp=find(strcmp({EEG.chanlocs.labels}, 'VEOGp'));
end
EEG=pop_rejchanspec(EEG, 'plotchans', 'on','stdthresh',3, 'elec', [1:(chHEOGn-1) (chVEOGp+1):EEG.nbchan]); % los valores de los indices de los canales varían en función de si se han eliminado canales
pause(25)
eegplot();
%% Aplicar análisis ICA a todos los canales excepto VEOG y HEOG
EEG = pop_runica(EEG, 'icatype', 'runica', 'extended',1,'interupt','on','chanind',[1:(chHEOGn-1) (chVEOGp+1):EEG.nbchan]);%los valores de los indices tras chanind se cambian si se han eliminado canales, OJO en PAC02 que se elimina VEOGp
% Guardar datos en formato .set y .fdt
nombre=sujeto+"_5min.previos_ICA_refA2";
EEG.setname = nombre;
filename=char(nombre+set_sufix);
EEG = pop_saveset(EEG, 'filename',filename , 'filepath', ruta);
EEG = pop_iclabel(EEG, 'default');
% Marcar como artefactos aquellos componentes que se deban en menos de un 10% al cerebro:
% thresh - array with threshold values with limits to include for selection as artifacts.
% The 6 categories are (in order) Brain, Muscle, Eye, Heart, Line Noise, Channel Noise, Other.
EEG = pop_icflag(EEG, [0 0.1;NaN NaN;NaN NaN;NaN NaN;NaN NaN;NaN NaN;NaN NaN]);
EEG = pop_subcomp( EEG, [], 0);
nombre=nombre+"done";
EEG.setname=nombre;
filename=char(nombre+set_sufix);
EEG = pop_saveset(EEG, 'filename', filename , 'filepath', ruta);
%% Acotar amplitudes
a=size(EEG.icaact,100);
pop_eegthresh(EEG,0,1:a,-100,100,-0.2,0.2, 1, 1);
pause(10);
%% Filtrado en banda de interés
m=EEG.chanlocs.labels; %por si se ha eliminado algún canal
EEG = pop_eegfiltnew(EEG, 'locutoff',0.5,'hicutoff',50,'plotfreqz',1,'channels',cellstr(m));
nombre=nombre+"_filt";
EEG.setname=nombre;
filename=char(nombre+set_sufix);
EEG = pop_saveset(EEG, 'filename', filename , 'filepath', ruta);
%% Obtener épocas del EEG continuo
EEG=eeg_regepochs(EEG, 'recurrence', 2, 'limits', [0 2]); %al ser espectro continuo, hay que usar esta función que genera eventos aleatorios para poder extraer las épocas
nombre=nombre+"_epochs";
EEG.setname=nombre;
filename=char(nombre+set_sufix);
EEG = pop_saveset(EEG, 'filename', filename , 'filepath', ruta);
%% Guardar imágenes
rutaGeneral='C:\Users\rebec\OneDrive\Escritorio\DATOS-EEG\PACIENTES\';
rutaEspecifica=sujeto;
rutaArchivo=rutaGeneral+rutaEspecifica;
%% Estudiar espectro de potencia del paciente en 5 mins previos
rango=[1 30];
intervalo_temporal=[0 300];
frecuencias_delta=1 : 4;
frecuencias_theta=4:8;
frecuencias_alpha=8:12;
frecuencias_beta1=12:19;
frecuencias_beta2=20:25;
frecuencias_beta3=26:30;
delta=figure; pop_spectopo(EEG, 1, intervalo_temporal, 'EEG' , 'freq', frecuencias_delta, 'freqrange',rango,'electrodes','off');
nombreArchivo="Espectro potencia delta 5mins relax";
saveas(delta, rutaArchivo+nombreArchivo, 'jpeg');
theta=figure; pop_spectopo(EEG, 1, intervalo_temporal, 'EEG' , 'freq', frecuencias_theta, 'freqrange',rango,'electrodes','off');
nombreArchivo="Espectro potencia theta 5 mins relax";
saveas(theta, rutaArchivo+nombreArchivo, 'jpeg');
alpha=figure; pop_spectopo(EEG, 1, intervalo_temporal, 'EEG' , 'freq', frecuencias_alpha, 'freqrange',rango,'electrodes','off');
nombreArchivo="Espectro potencia alpha 5 mins relax";
saveas(alpha, rutaArchivo+nombreArchivo, 'jpeg');
beta1=figure; pop_spectopo(EEG, 1, intervalo_temporal, 'EEG' , 'freq', frecuencias_beta1, 'freqrange',rango,'electrodes','off');
nombreArchivo="Espectro potencia beta1 5 mins relax";
saveas(beta1, rutaArchivo+nombreArchivo, 'jpeg');
beta2=figure; pop_spectopo(EEG, 1, intervalo_temporal, 'EEG' , 'freq', frecuencias_beta2, 'freqrange',rango,'electrodes','off');
nombreArchivo="Espectro potencia beta2 5 mins relax";
saveas(beta2, rutaArchivo+nombreArchivo, 'jpeg');
beta3=figure; pop_spectopo(EEG, 1, intervalo_temporal, 'EEG' , 'freq', frecuencias_beta3, 'freqrange',rango,'electrodes','off');
nombreArchivo="Espectro potencia beta3 5 mins relax";
saveas(beta3, rutaArchivo+nombreArchivo, 'jpeg');
% Análisis de potencia espectral
name='PAC01_5min.previos_ICA_refA2done_filt_epochs'+'eegstats';
pop_eegstats(EEG, 'thetarange',[4 8],'alpharange',[8 12], 'otherranges', [1 4; 12 30; 30 50], 'averagepower', 'off', 'channels', (11):(63),'csvfile', 'PAC01_eegstats', 'iaf', 'off' );
0 Comments
Accepted Answer
Rik
on 22 Aug 2024
Edited: Rik
on 22 Aug 2024
Short answer:
The hamming function is part of a toolbox you apparently didn't install. In this case the signal processing toolbox.
Longer answer:
You have trouble with Matlab basics and you may consider doing the Onramp tutorial (which is provided for free by Mathworks).
What you are doing in this line:
name='PAC01_5min.previos_ICA_refA2done_filt_epochs'+'eegstats';
is incorrect. You are not concatenating (merging) the two arrays, you are adding them together. And since they are different lengths, that doesn't work. It can be used sometimes:
% this does strange things with the space, use upper() instead if you want
% to convert to upper case
disp(char('some text here'-'a'+'A'))
'This is a char vector'
"This is a string scalar"
["And this","is a string vector"]
The second reason I give my advise of doing Onramp is how you tried to create the hamming function. This is no how that works. Let's look at it step-by-step:
function w = hamming(L)
w = hamming(L,sflag)
end
First you create a function with one output and one input, named hamming. So far so good. Now you call the function hamming with one output and two inputs. That is fine, as long as you don't mind an infinite recursion. You just created the function hamming and are immediately calling it. The way you were avoiding an infinite recursion is that were using a second input argument, which you didn't actually provide.
Small things I noticed:
More Answers (0)
See Also
Categories
Find more on EEG/MEG/ECoG 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!