How can I fill an empty matrix?

2 次查看(过去 30 天)
% Hi everyone I am trying to classfify a matrix M=21x2560 from an EEG. My aim is to divide the 21 channels into four different empty matrix. How can I fill temporal, occipital, parietal and frontal?. Then, I want to do the mean of every matrix created before. If I use "mean" only one value comes up but I want one value for each column of the matrix. Pleasee helpp meee! Thankyouuu!
load AD1.mat
M=X; [n,m]=size(M);
Temporal=[]; Frontal=[]; Parietal=[]; Occipital=[];
for i=1:n
c=M(i:2520);
signal=c;
Fs=128;
band=[1 60];
frequency_band=[1 4; 4 8; 8 13; 13 30; 30 40];
[ RelativePower ] = Compute_RP( signal,Fs,band,frequency_band);
RP_c=RelativePower;
if i==8 || i==13 || i==3 || i==4 || i==9 ||i==14
Temporal=[RP_c];
end
if i==1 || i==20 || i==2 || i==5 || i==6 ||i==7
Frontal=[RP_c];
end
if i==10 || i==11 || i==12 || i==15 || i==16 ||i==17
Parietal=[RP_c];
end
if i==18 || i==21 || i==19
Occipital=[RP_c];
end
end
RP_Temporal=Temporal; RP_Frontal=Frontal; RP_Parietal=Parietal; RP_Occipital=Occipital;
figure; bar(RP_Temporal); title('Relative Power Temporal lobe')
figure; bar(RP_Frontal); title ('Relative Power Frontal lobe')
figure; bar(RP_Parietal); title('Relative Power Parietal lobe')
figure; bar(RP_Occipital); title ('Relative Power Occipital lobe')

回答(1 个)

Harish Ramachandran
Harish Ramachandran 2017-12-28
There are two points to note:
1. The piece of code below will overwrite Temporal's existing value at different values of i (with value of RP_c). Instead from your question, I gather that your requirement is to concatenate the value of Temporal with the i'th column of RP_c
if i==8 || i==13 || i==3 || i==4 || i==9 ||i==14
Temporal=[RP_c];
end
In order to concatenate the values, do take a look at this link . Your code would look something like this:
if i==8 || i==13 || i==3 || i==4 || i==9 ||i==14
Temporal =[ Temporal RP_c(:,i) ];
end
2. With respect to your statement:
If I use "mean" only one value comes up but I want one value for each column of the matrix.
Once the values are filled up and you get a matrix with N columns, you can calculate the mean of each column using the mean function.
>> x = rand(50,5);
>> Y = mean(x)
Y =
0.5413 0.5499 0.4918 0.4321 0.5170
Hope this helps.

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by