avoid dinamic variable names in for loops
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello everyone,
I am having trouble in creating variables names in a seemingly "reasonable" way. I know the principle behind (no eval, no dinamic variable name, etc), but i can't figure out how to solve the issue.
Someone among you could even argue against the use of for loop. In that case, please provide an alternative solution using matrix indexing.
The rationale behind this script is to extract powers band values from a LFP (similar to an EEG signal). TD_32 is a 3D matrix.
The signal was captured by a linear probe having 32 channels. This big picture: I deliver a stimulus. The signal being captured is a continuos time series. As a pre-processing steps, i had cut the time series in order to have a 3d matrix, where the third dimension are the different repetition (epochs), the second the channels which collect the signal from different sources and the first dimension being the actual signal.
I need to get the powers results (stored in different bands width as shown in the code) from all the channels and store them into different variables, or a matrix (i don't know what the best solution could be)
F = 0.5:0.1:150; %frequency range in Hz
delta = [0.5 4];
theta = [4 8];
alpha = [8 12];
beta = [12 25];
gamma = [25 80];
for ch=10:29
matr_500_post = mean(TD_32(:,ch,:),3);
[pxx_n_new_4,hz_n_new_4] = pwelch(matr_500_post,window,[],F, srate); % post stim
[~,fidx(1)] = min(abs(hz_n_new_4-delta(1) ));
[~,fidx(2)] = min(abs(hz_n_new_4-delta(2) ));
avpow_delta = mean(pxx_n_new_4(fidx(1):fidx(2)));
[~,fidx(1)] = min(abs(hz_n_new_4-theta(1) ));
[~,fidx(2)] = min(abs(hz_n_new_4-theta(2) ));
avpow_theta = mean(pxx_n_new_4(fidx(1):fidx(2)));
[~,fidx(1)] = min(abs(hz_n_new_4-alpha(1) ));
[~,fidx(2)] = min(abs(hz_n_new_4-alpha(2) ));
avpow_alpha = mean(pxx_n_new_4(fidx(2):fidx(2)));
[~,fidx(1)] = min(abs(hz_n_new_4-beta(1) ));
[~,fidx(2)] = min(abs(hz_n_new_4-beta(2) ));
avpow_beta = mean(pxx_n_new_4(fidx(1):fidx(2)));
[~,fidx(1)] = min(abs(hz_n_new_4-gamma(1) ));
[~,fidx(2)] = min(abs(hz_n_new_4-gamma(2) ));
avpow_gamma = mean(pxx_n_new_4(fidx(1):fidx(2)));
powers_500ms_post = [avpow_delta,avpow_theta,avpow_alpha,avpow_beta,avpow_gamma];
end
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!