Save values in a for loop
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (2 件)
the cyclist
2014 年 9 月 19 日
Don't you want the line
allpowervalues(:,ii)= powervalue;
inside the for loop?
0 件のコメント
Eric
2014 年 9 月 19 日
4 件のコメント
the cyclist
2014 年 9 月 19 日
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?
参考
カテゴリ
Help Center および File Exchange で EEG/MEG/ECoG についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!