我一直在尝试使用此代码将 x 轴值(仅限峰值)写入 txt 文件(此方法有效)。
%determine the bpm
%count the dominant peaks in the signal
fid = fopen('y1.txt','a'); %txt naming and append
beat_count = 0;
for k = 2 : length(pbcg)-1
if (pbcg(k) > pbcg(k-1) && pbcg(k) > pbcg(k+1) && pbcg(k) > 1)
beat_count = beat_count + 1;
end
end
fprintf(fid, '%i\n', k); %open writer
fs = 100; %freq 100hz
N = length(pbcg);
duration_in_seconds = N/fs;
duration_in_minutes = duration_in_seconds/60;
BPM_avg = beat_count/duration_in_minutes;
fclose(fid); %close writer
但是当我修改它以逐段绘制图形时问题就出现了(我设法完成了这个)但是当我的代码是这样时,问题无法将 x 轴值写入 txt 文件。 . 我做错了什么?
%plot segment by segment
data = pbcg;%data value from 1 to 10000
rows = reshape(data, 1000, numel(data)/1000)';%reshape the data into
%matrix by 1000 against total num of element in array and then / 1000)
fid = fopen('y1.txt','a'); %txt naming and append
beat_count = 0;
for e = 1:size(rows,1),
%plot normal & with nodes together
figure,plot(rows(e,:)),hold on,plot(rows(e,:),'ro');
%if statement to find peak
if (pbcg(k) > pbcg(k-1) && pbcg(k) > pbcg(k+1) && pbcg(k)> input('Key in the threshold value: '))
beat_count = beat_count + 1;
peaks(beat_count)=pbcg(k);
end
pause;%pause, on keypress go to next plot
fprintf(fid, 'x_axis%i\n ', peaks); %open writer
end
fclose(fid); %close writer
即使在我输入阈值之后,我得到的结果也是整个峰值列表。