符合这些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'
,但它全部停留在1处)
由于图表被分段到每个1000
,是否可以增加x轴上的值?就像第一个图是0
到1000
,第二个图是1001
到2000
等等,直到整个数据长度。
允许用户输入他们想要启动的任何细分,例如我可以键入一个值,这样我就可以从3001
到4000
进行绘图,每次输入阈值后值将它将输出写入文本文件,而不是将所有输出写入文本文件的所有内容。 (如果中途发生任何错误,你需要重做所有内容,这样可以防止重复整个过程,如果发生了中途,我也可以从停止的地方开始)
答案 0 :(得分:0)
绘图函数有两个参数,x值和y值。如果要从0到1000绘图,请设置x值:
x = ((e-1)*1000):(e*1000);
plot(x, rows(e,:));
...
为了将'o'绘制在正确的x值,请包含x参数:
plot(peak_x(beat_count), rows(e,peak_x(beat_count)),'ro');
...
如果您想在每次用户完成细分时将数据打印到文件,请打开文件以便在上一行后面追加:
fid = fopen('OUTPUTFILE.txt', 'at');
fprintf(fid, 'x = %d; peak = %f\n', peak_x(beat_count), peaks(beat_count));
fclose(fid);