簡體   English   中英

MATLAB數據光標模式

[英]MATLAB Data Cursor Mode

我有一個簡單的類,可以繪制基本的x和y數據。 在該類中,我有一個啟用數據光標模式,自定義文本以及收集和保存點的方法。 我想更改該方法的行為,以便一次只能收集兩個點。 現在,即使我關閉了數據光標模式並重新打開以使用它,它也會存儲每個點。 這是我上課的代碼:

classdef CursorPoint


    properties
        Xdata
        Ydata
    end

    methods
        function me = CursorPoint(varargin)

            x_data = 0:.01:2*pi;
            y_data = cos(x_data);
            f= figure;
            plot(x_data,y_data);
            me.DCM(f);

        end

        function DCM(me,fig)
            dcm_obj = datacursormode(fig);

            set(dcm_obj,'UpdateFcn',@myupdatefcn)
            set(dcm_obj,'enable','on')
            myPoints=[];

            function txt = myupdatefcn(empt,event_obj)
                % Customizes text of data tips

                pos = get(event_obj,'Position');
                myPoints(end + 1,:) = pos;
                txt = {['Time: ',num2str(pos(1))],...
                    ['Amplitude: ',num2str(pos(2))]};

            end

        end

    end
end

您能否將myPoints變量更改為兩個名為myPointCurrentmyPointPrevious變量。 每當調用myupdatefcn方法時,您都將myPointCurrent的內容移動到myPointPrevious ,然后將當前位置存儲在myPointCurrent

新功能(帶有一些錯誤檢查)將類似於:

function txt = myupdatefcn(empt,event_obj)
    % Customizes text of data tips
    myPointPrevious=myPointCurrent;

    pos = get(event_obj,'Position');
    myPointCurrent=pos;

    txt = {['Time: ',num2str(pos(1))],...
        ['Amplitude: ',num2str(pos(2))]};
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM