【发布时间】:2013-07-10 10:18:25
【问题描述】:
在满足Matlab plot graph(segment by segment) and user input threshold value before writing to txt 和Matlab load entire file but show and plot segment by segment 的标准后,我有新问题
我的任务是绘制图表并显示峰值节点(那些 > 阈值),但只设法绘制节点并且它卡在这里:
我正在尝试绘制这张图片显示的内容,但我遇到了困难:
这是我的代码:
for e = 1:size(rows,1),
%plot normal graph first, hold it before plotting nodes
%so that it is combined
figure,plot(rows(e,:)), hold on;
%put the 'INPUT' statement outside the loop, or it will be evaluated
%multiple times (every time all the other conditions are true)
threshold = input('Key in the threshold value to use: ');
% loop over this if statement to find peaks in this row
for k = 2 : 999
if (rows(e,k) > rows(e, k-1) && rows(e,k) > rows(e,k+1) && rows(e,k) > threshold)
beat_count = beat_count + 1;
peaks(beat_count)=rows(e,k);
peak_x(beat_count) = k + 1000 * (e - 1);
plot(rows(e,peak_x(beat_count)),'ro');
end
end
%pop up text to plot new segment
fprintf(1, 'press any key to continue!\n');
% pause, on keypress go to next plot
pause;
end
% since peaks array keeps growing, we should print it out all at once:
fprintf(fid, 'the following peaks were found:\n');
for ii = 1:beat_count
fprintf(fid, 'x = %d; peak = %f\n ', peak_x(ii), peaks(ii)); %open writer
end
fclose(fid); % close the file once you're done
我实际上有 3 个问题,但我想一个一个地解决它。所以前 1 个将是
绘制图形并将峰值节点
'O'显示为 > 大于 用户输入的阈值(我设法绘制了峰值'O',但它都卡在了一个地方)由于图形被分割成每个
1000,是否可以增加 x 轴上的值?就像第一个图是从0到1000,第二个图是从1001到2000,依此类推,直到数据的整个长度。允许用户从他们想要开始的任何部分输入,例如,我可以键入一个值,因此我将从
3001绘制到4000并且每次键入阈值后它都会写入输出到文本文件,而不是最后将所有输出写入文本文件。 (如果中途出现任何错误,你需要重做所有事情,这样可以防止如果中途出现问题,我也可以从停止的地方开始重复整个过程)
【问题讨论】: