Matlab:为多个数据集的数据光标添加附加信息

时间:2015-02-19 17:16:33

标签: matlab matlab-figure

我正在尝试在类似于1的图中向光标添加其他数据,但是,我有多个数据集。如何从两个数据集中提取数据光标。

function test
    x1 = 1:10;
    x2 = 1:0.5:10;

    y1 = cos(x1);
    y2 = sin(x2);

    z1 = rand(size(x1));
    z2 = rand(size(x2));

    fig = figure;
    plot(x1, y1, x2, y2)
    dcm_obj = datacursormode(fig);
    datacursormode on

    set(dcm_obj,'updatefcn',{@myupdatefcn, {z1, z2}})
end

function txt = myupdatefcn(x,event_obj,t)
    % Customizes text of data tips
    pos = get(event_obj,'Position');
    I = get(event_obj, 'DataIndex');
    txt = {['V: ',num2str(pos(1))],...
           ['j: ',num2str(pos(2))],...
           ['z: ',num2str(t(I))]};
end

0 个答案:

没有答案