【问题标题】:matlab plot graph (only show >threshold)matlab绘图图(仅显示>阈值)
【发布时间】:2013-07-10 10:18:25
【问题描述】:

在满足Matlab plot graph(segment by segment) and user input threshold value before writing to txtMatlab 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 个将是

  1. 绘制图形并将峰值节点 'O' 显示为 > 大于 用户输入的阈值(我设法绘制了峰值'O',但它都卡在了一个地方)

  2. 由于图形被分割成每个1000,是否可以增加 x 轴上的值?就像第一个图是从01000,第二个图是从10012000,依此类推,直到数据的整个长度。

  3. 允许用户从他们想要开始的任何部分输入,例如,我可以键入一个值,因此我将从3001 绘制到4000 并且每次键入阈值后它都会写入输出到文本文件,而不是最后将所有输出写入文本文件。 (如果中途出现任何错误,你需要重做所有事情,这样可以防止如果中途出现问题,我也可以从停止的地方开始重复整个过程)

【问题讨论】:

    标签: matlab plot


    【解决方案1】:

    plot 函数有两个参数,x 值和 y 值。如果要从 0 到 1000 绘制,请设置 x 值:

    x = ((e-1)*1000):(e*1000);
    plot(x, rows(e,:));
    ...
    

    为了在正确的 x 值处绘制 'o',请包含 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多