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

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.
Elaheh
Elaheh 2020년 8월 14일
Thank you,
No, the order of labes is different in each file, so I need to average across lables of channels that are the same in all files, I need to average ChFP1, ChF7, ChF3, ChFT7, ChFC3) and other combination of electrod lables.
I appreicipate your help.
Zahra

댓글을 달려면 로그인하십시오.

 채택된 답변

KSSV
KSSV 2020년 8월 14일

0 개 추천

Use readtable. This is suggested now.
T = readtable(filename) ;
mean_ChF7 = mean(T.ChF7)

댓글 수: 6

Elaheh
Elaheh 2020년 8월 14일
Thank you for your reply.
In fact, I need to do this, but it did not work.
T = readtable(fileName) ;
mean_LA = mean(T.ChFP1,T.ChF7,T.ChF3,T.ChFT7,T.ChFC3);
Zahra
mean_LA = [mean(T.ChFP1) mean(T.ChF7) mean(T.ChF3) mean(T.ChFT7) mean(T.ChFC3)];
OR
mean_LA = mean([T.ChFP1 T.ChF7 T.ChF3 T.ChFT7 T.ChFC3]);
Elaheh
Elaheh 2020년 8월 14일
The problem with these two lines is that they give me 5 values, one for each channel. In fact, I need 22 values one for each participant for these 5 channels. in other words, I need to average across the rows and not across columns.
Please see the attached file.
Zahra
mean_LA = mean([T.ChFP1 T.ChF7 T.ChF3 T.ChFT7 T.ChFC3],2);
KSSV
KSSV 2020년 8월 14일
OP commented: It works. Thank you so much. What is 2 for?
KSSV
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개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2019a

태그

질문:

2020년 8월 14일

댓글:

2020년 8월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by