2013-07-10 120 views
1

我從這些Matlab plot graph(segment by segment) and user input threshold value before writing to txtMatlab load entire file but show and plot segment by segmentMATLAB繪圖表(只顯示>閾值)

我的任務是繪製圖形和顯示的高峯節點滿足條件後,新的問題(這些是>閾值),但只管理繪製的節點,它是被困在這裏:

what I can

我試圖繪製出來這是什麼PIC節目,但我有困難:

what I want

這裏是我的代碼:

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所以第1會

  1. 繪製圖形和顯示峯值節點'O'與那些超過用戶輸入的閾值 (我設法繪製峯值'O',但它們都卡在1個位置)

  2. 由於圖正在分割成每個1000,是否可以增加x軸上的值?像第一個圖從01000,第二個圖將從10012000等等,直到數據的整個長度。

  3. 允許從他們要開始,比如我可以在一個重視關鍵,所以我會從3001密謀4000取其段的用戶輸入,以後每次在閾值I鍵將輸出寫入到文本文件而不是將所有輸出全部寫入文本文件。 (如果有什麼差錯中途發生,則需要重新一切,所以這是從重複整個流程,以防止如果事情中途發生,我可以從我停止開始,太)

回答

0

情節函數有兩個參數,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);