Hi all,
I trying to create a script that is able to save the values from each run in a 'for loop' for an EEG study. It works very well without the loop (stores values correct in 'powervalue'). The problem is that it's only saving the last value in the 'allpowervalues':
powervalue = zeros(length(freq),1);
allpowervalues = zeros(length(freq),12);
for ii=1:length(freq)
% Script calculating power values for EEG
end
allpowervalues(:,ii)= powervalue;
I hope someone can help.
Christian

답변 (2개)

the cyclist
the cyclist 2014년 9월 19일

1 개 추천

Don't you want the line
allpowervalues(:,ii)= powervalue;
inside the for loop?
Eric
Eric 2014년 9월 19일

0 개 추천

Thank you for the response. I already did that but it still doesn't work.

댓글 수: 4

Stephen23
Stephen23 2014년 9월 19일
I guess you meant to write a comment to the cyclist's answer, rather than your own answer...
In any case, did you actually try what the cyclist suggests?
Eric
Eric 2014년 9월 19일
편집: Eric 2014년 9월 19일
That's correct. :) I tried the following:
powervalue = zeros(length(freq),1);
allpowervalues = zeros(length(freq),12);
for ii=1:length(freq)
% Script calculating power values for EEG
allpowervalues(:,ii)= powervalue;
end
This code fills in the entire array for me:
freq = rand(4,1);
powervalue = zeros(length(freq),1);
allpowervalues = zeros(length(freq),12);
for ii=1:12
powervalue = rand(4,1);
allpowervalues(:,ii)= powervalue;
end
I did change your for loop to go from 1:12 instead of 1:length(freq). Maybe that was part of the problem?
Eric
Eric 2014년 9월 22일
Thank you very much for your answer. I finally works.

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

카테고리

도움말 센터File Exchange에서 EEG/MEG/ECoG에 대해 자세히 알아보기

질문:

2014년 9월 19일

댓글:

2014년 9월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by