クリックしたときにデータポイントとともに情報を表示するカスタマイズされたプロット関数を作成しています。関数への入力は、ポイントと共に表示される情報を持つ Figure と (情報と同じサイズの) 配列です。
これが私がこれまでに持っているものです:
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
問題は、1 次元配列がある場合にのみ情報が正しく表示されることです。それ以外の場合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
結果のグラフには 3 本の線があり、 をクリックすると0.2、Bコマンド ウィンドウに表示されます。