我正在使用 Matlab R2020b,当将光标悬停在 2D 图中的数据点上时,我想显示其他信息。我有极坐标图的角度和半径值。每个数据点都与时间相关联。我创建类似于这样的情节:
t = linspace(0, 1, 100);
phi = 2*pi*t;
r = t.^2+1;
h = figure;
polarplot(phi, r, '-sb');
dcm = datacursormode(h);
datacursormode on;
set(dcm, 'updatefcn', @myfunction);
function output_txt = myfunction(obj,event_obj)
% Display data cursor position in a data tip
% obj Currently not used
% event_obj Handle to event object
% output_txt Data tip text, returned as a character vector or a cell array of character vectors
pos = event_obj.Position;
%********* Define the content of the data tip here *********%
% Display the x and y values:
output_txt = {['\phi: ' num2str(pos(1)*180/pi) '°'],...
['r: ' num2str(pos(2))]};
%***********************************************************%
% If there is a z value, display it:
if length(pos) > 2
output_txt{end+1} = ['Z',formatValue(pos(3),event_obj)];
end
%***********************************************************%
end
理想情况下,我希望为我选择的任何数据点显示(角度、半径、时间)的三元组。有关自定义数据提示的信息并没有告诉我如何添加另一个变量(时间)的值,只有在使用 3D 绘图(例如 plot3.
你知道这个问题的任何解决方案吗?