Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help figuring out how adjust a forloop to make a new vector called aavp w

ID: 3885192 • Letter: I

Question

I need help figuring out how adjust a forloop to make a new vector called aavp which holds the variable [avp1, avp2,...-avp14] for 14 channels per file. Here's my current code:

fileID=fopen('Alpha_loop.txt','wt');
fprintf(fileID,'filename channel avp length(min) ');
listOfFiles = dir('*.set');
numberOfFiles = length(listOfFiles);
Fs=128;
m=7680;

for jj = 1:numberOfFiles
f = listOfFiles(jj).name; %list of names
x = pop_loadset(f); %loads files
len =x.pnts; %length of each point
r=(len/128)/60;% converted to minutes
d=x.data;% pulls the data from each file
startpoints=1:m:len;
for channel = 1:14;
vp= [];
for k= startpoints(1:end-1)
b=bandpower(d(channel, k:(k+m)),Fs,[8 13])/ bandpower(d(channel, k:(k+m)), Fs, [1 41]); % gives you the alpha power per file
vp=[vp b];
end
avp = mean(vp); % finds the mean of the alpha power per file ( I need to section to per channel and put into new variable aavp)
fprintf(fileID,'%s %d %g %g ',f,channel,avp,r);
end
end
  
fclose(fileID);
type Alpha_loop.txt

Explanation / Answer

Added the array inside the first for loop.

PROGRAM CODE:

fileID=fopen('Alpha_loop.txt','wt');

fprintf(fileID,'filename channel avp length(min) ');

listOfFiles = dir('*.set');

numberOfFiles = length(listOfFiles);

Fs=128;

m=7680;

for jj = 1:numberOfFiles

f = listOfFiles(jj).name; %list of names

x = pop_loadset(f); %loads files

len =x.pnts; %length of each point

r=(len/128)/60;% converted to minutes

d=x.data;% pulls the data from each file

startpoints=1:m:len;

//Array that stores the avp values

aavp = [];

for channel = 1:14;

vp= [];

for k= startpoints(1:end-1)

b=bandpower(d(channel, k:(k+m)),Fs,[8 13])/ bandpower(d(channel, k:(k+m)), Fs, [1 41]); % gives you the alpha power per file

vp=[vp b];

end

avp = mean(vp); % finds the mean of the alpha power per file ( I need to section to per channel and put into new variable aavp)

%indexing and storing values

aavp(channel) = {avp};

fprintf(fileID,'%s %d %g %g ',f,channel,avp,r);

end

end

  

fclose(fileID);

type Alpha_loop.txt

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote