1

我正在编写一个自定义绘图函数,该函数在单击时显示信息以及数据点。该函数的输入是图形和一个数组(与信息大小相同),其中包含要与点一起显示的信息。

这是我到目前为止所拥有的:

function  textPlot( fh, text_v )

    dcm=datacursormode(fh);
    datacursormode on
    set(dcm,'updatefcn',{@myfunction,text_v})

function output_txt = myfunction(obj,event_obj,text_v)

    % Display the position of the data cursor
    % obj          Currently not used (empty)
    % event_obj    Handle to event object
    % output_txt   Data cursor text string (string or cell array of strings).

    pos = get(event_obj,'Position');

    disp(text_v(pos(1)))
    output_txt = {['X: ',num2str(pos(1),4)],...
                  ['Y: ',num2str(pos(2),4)]};

    % If there is a Z-coordinate in the position, display it as well
    if length(pos) > 2
        output_txt{end+1} = ['Z: ',num2str(pos(3),4)];
    end

问题是信息只有在存在一维数组时才能正确显示。否则disp(text_v(pos(1)))将仅显示第一列中的信息。

简而言之,有没有办法获取图例索引?


例如,如果值的 是:

0.1 0.2 0.4
0.5 0.7 0.6
0.8 0.9 0.0

对应的文本信息为:

A B C
D E F
G H I

那么结果图应该有三行,当我点击时0.2B应该显示在命令窗口中

4

1 回答 1

0

为了获得显示中的值text_v,您首先需要在values矩阵中找到与中选择的值匹配的索引pos

pos = [..., ...];
disp(text_v(values(:)==pos(2));
于 2014-07-17T11:49:08.240 回答