average selected columns with labels
1 回表示 (過去 30 日間)
古いコメントを表示
hello all,
I have the attached data. It shows a part of my data. I need to average selected coumns in red only. I need to tell matlab that average electrodes such as ChFP1, ChF7, ChF3, and ChFT7, across subjects and write the resluts in one column at the end of data. How should I do that? I wrote this so far. Thank you in advance. I tried to creat a logical index but could not with a cell array.
if exist(fileName,'file')
[num,str]=xlsread(fileName); %read both str and data
ch_lables=(str(1,:)); %electrode lables, cell array
sub_names=str(:,1); %subjects names, cell array
end
2 件のコメント
Sara Boznik
2020 年 8 月 14 日
Hi,
if you know where are red numbers, try this
a=num(:,4)
b=num(:,7)
c=num(:,11)
d=num(:,12)
A=[a;b;c;d]
[n,m]=size(A)
for i=1:1:n
s(i)=a(i)+b(i)+c(i)+d(i)
avrg=s(i)/4
fprintf(fileName(:,15),'%.4f\n',avrg)
end
I wish that this will help you and good luck.
採用された回答
KSSV
2020 年 8 月 14 日
Use readtable. This is suggested now.
T = readtable(filename) ;
mean_ChF7 = mean(T.ChF7)
6 件のコメント
KSSV
2020 年 8 月 14 日
2 stands for mean along each row..this what you wanted. DEfault is 1, which is mean along each column.
NOTE: You have to accept/ vote the answer which worked for you. Not that you comment and accept that. :)
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!