Loop calculation and output
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
i have 170 files of eeg recording. i want output of each file to be stored in a seperate excel file. i am not sure how to do this. pls help
My code to initiate is as below:
txtFiles = dir('*.txt') ;
l=length(txtFiles);
N = l*10 ;
Bandsheet = zeros(N,8);
PSDSheet1 =zeros(N,16);
PSDSheet2 =zeros(N,16);
PSDSheet3 =zeros(N,16);
for n=1:170
filename = ['00000460_', int2str(n), '.txt'];
x=load(filename);
figure;
채택된 답변
Yongjian Feng
2022년 2월 11일
You meant this:
txtFiles = dir('*.txt') ;
l=length(txtFiles);
N = l*10 ;
Bandsheet = zeros(N,8);
PSDSheet1 =zeros(N,16);
PSDSheet2 =zeros(N,16);
PSDSheet3 =zeros(N,16);
for n=1:170
filename = ['00000460_', int2str(n), '.txt'];
x=load(filename);
figure;
% then you are going to update Bandsheet, PSDSheet1, etc here?
% and you want to write them into different excel files?
fname = ['00000460_', int2str(n), '.xlsx'];
writetable(Bandsheet, fname, 'Sheet', 'Bandsheet');
writetable(PSDSheet1, fname, 'Sheet', 'PSDSheet1');
writetable(PSDSheet2, fname, 'Sheet', 'PSDSheet2');
writetable(PSDSheet3, fname, 'Sheet', 'PSDSheet3');
end
댓글 수: 6
siri meka
2022년 2월 11일
% this will give you all test files names
txtFiles = dir('*.txt') ;
l=length(txtFiles);
N = l*10 ;
Bandsheet = zeros(N,8);
PSDSheet1 =zeros(N,16);
PSDSheet2 =zeros(N,16);
PSDSheet3 =zeros(N,16);
for n=1:2
filename = ['00000460_', int2str(n), '.txt'];
x=load(filename);
figure;
x=load(filename);
ab= x2(0001:24000);
%%band power%%
delta = bandpower(ab,24000, [1 4]);
theta = bandpower(ab,24000,[4 8]);
alpha = bandpower(ab,24000,[8 12]);
low_beta = bandpower(ab,24000,[12 20]);
high_beta = bandpower(ab,1000,[20 35]);
beta = bandpower(ab,24000,[12 35]);
gamma = bandpower(ab,24000,[35 80]);
HFO= bandpower (ab,24000,[200 300]);
bandcomplete1 = [delta theta alpha low_beta high_beta beta gamma HFO]
Fs=24000;
N=ceil(log2(length(ab)));
L=length(ab);
%%Delta Filtering and Spectrum%%
delta1 = bandpass(ab,[1 4],1000);
figure
delta2= fft(delta1,2^N)/(L/2);
if isreal(ab)==0
fy=fy/2;
end
Power=delta2.*conj(delta2);
phy=angle(delta2);
% Frequency axis
f=(Fs/2^N)*(0:2^(N-1)-1);
%if nargin==4
deltapower= Power(1:2^(N-1));
% Find local maxima
maxIndices = islocalmax(deltapower,'MaxNumExtrema',3,'SamplePoints',f);
% Display results
clf
plot(f,deltapower,'Color',[109 185 226]/255,'DisplayName','Input data')
hold on
% Plot local maxima
plot(f(maxIndices),deltapower(maxIndices),'^','Color',[217 83 25]/255,...
'MarkerFaceColor', [217 83 25]/255, 'DisplayName', 'Local maxima')
hold off
deltavalue = plot(f(maxIndices),deltapower(maxIndices), '*','Color',[20 83 20]/255,...
'MarkerFaceColor', [55 83 25]/255, 'DisplayName', '.')
legend
x=get(deltavalue,'XData') ;
y=get(deltavalue,'YData') ;
disp(x)
disp(y)
t= [x;y]
sorted_delta = sortrows(t',2,'descend')
AllPSD2= [sorted_delta sorted_theta sorted_alpha sorted_lowbeta sorted_highbeta sorted_beta sorted_gamma sorted_hfo ]
psd11 = AllPSD2 (1,:)
psd12 = AllPSD2 (2,:)
psd13 = AllPSD2(3,:)
Bandsheet (n,:) = bandcomplete2;
PSDSheet1 (n,:) =psd21;
PSDSheet2 (n,:) =psd22;
PSDSheet3 (n,:) =psd23;
ab= x2(24001:48000);
%%band power%%
delta = bandpower(ab,24000, [1 4]);
theta = bandpower(ab,24000,[4 8]);
alpha = bandpower(ab,24000,[8 12]);
low_beta = bandpower(ab,24000,[12 20]);
high_beta = bandpower(ab,1000,[20 35]);
beta = bandpower(ab,24000,[12 35]);
gamma = bandpower(ab,24000,[35 80]);
HFO= bandpower (ab,24000,[200 300]);
disp (delta);
disp (theta);
disp (alpha);
disp (low_beta);
disp (high_beta);
disp (beta);
disp (gamma);
disp (HFO);
bandcomplete2 = [delta theta alpha low_beta high_beta beta gamma HFO]
%%Delta Filtering and Spectrum%%
delta1 = bandpass(ab,[1 4],1000);
figure
delta2= fft(delta1,2^N)/(L/2);
if isreal(ab)==0
fy=fy/2;
end
Power=delta2.*conj(delta2);
phy=angle(delta2);
% Frequency axis
f=(Fs/2^N)*(0:2^(N-1)-1);
%if nargin==4
deltapower= Power(1:2^(N-1));
% Find local maxima
maxIndices = islocalmax(deltapower,'MaxNumExtrema',3,'SamplePoints',f);
% Display results
clf
plot(f,deltapower,'Color',[109 185 226]/255,'DisplayName','Input data')
hold on
% Plot local maxima
plot(f(maxIndices),deltapower(maxIndices),'^','Color',[217 83 25]/255,...
'MarkerFaceColor', [217 83 25]/255, 'DisplayName', 'Local maxima')
hold off
deltavalue = plot(f(maxIndices),deltapower(maxIndices), '*','Color',[20 83 20]/255,...
'MarkerFaceColor', [55 83 25]/255, 'DisplayName', '.')
legend
x=get(deltavalue,'XData') ;
y=get(deltavalue,'YData') ;
disp(x)
disp(y)
t= [x;y]
sorted_delta = sortrows(t',2,'descend')
AllPSD2= [sorted_delta sorted_theta sorted_alpha sorted_lowbeta sorted_highbeta sorted_beta sorted_gamma sorted_hfo ]
psd21 = AllPSD2 (1,:)
psd22 = AllPSD2 (2,:)
psd23 = AllPSD2(3,:)
Bandsheet (n+1,:) = bandcomplete2;
PSDSheet1 (n+1,:) =psd21;
PSDSheet2 (n+1,:) =psd22;
PSDSheet3 (n+1,:) =psd23;
siri meka
2022년 2월 11일
this is my actual code
ab= x2(0001:24000);
this x2(....) has to run till 24,00,000 in few files
and each 0000460_ needs to be saved as a different excel file with 4
sheets
siri meka
2022년 2월 11일
im into life sciences and dont have a clue about matlab.. tried this and its req for my thesis
Yongjian Feng
2022년 2월 11일
I see. Try the script posted above. It shall save those 4 sheets into an excel file.
siri meka
2022년 2월 11일
thanks a ton worked
Yongjian Feng
2022년 2월 11일
Great.
Accept the answer please then.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Bartlett에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
