How to add a variables name into a datatip

조회 수: 18 (최근 30일)
Renan Deuter
Renan Deuter 2022년 1월 18일
댓글: Renan Deuter 2022년 1월 18일
Hello,
I have measured some points and assigned names to them. Therefore I created a table "points" with the columns Name, X, Y, Z.
For example:
'L0.bag' 0.00366596578951730 -0.179678423557261 0.134501933438593
'L1.bag' 0.00672638008503305 0.243144532604341 -0.0422136590497351
Now I plot them with
scatter3(points.x, points.y, points.z, '*')
In order to compare different measurements I need to know which point is originally which.
Is there a way I can display the related name when I create a datatip?
I used this code in a different context but it does not seem to work here
dcm=datacursormode(fh);
datacursormode on
set(dcm, 'updatefcn',{@GeoDataTip, name })

채택된 답변

Adam Danz
Adam Danz 2022년 1월 18일
편집: Adam Danz 2022년 1월 18일
This demo consists of three 3D scatter points with labels 'a','b','c'.
% Create demo data
T = table({'a';'b';'c'},[1;2;3], [2;1;3], [3;2;1], ...
'VariableNames', {'Label','x','y','z'})
T = 3×4 table
Label x y z _____ _ _ _ {'a'} 1 2 3 {'b'} 2 1 2 {'c'} 3 3 1
% Plot 3D scatter
figure()
h = scatter3(T.x, T.y, T.z);
% Add labels
h.DataTipTemplate.DataTipRows(end+1) = dataTipTextRow('Label',T.Label);
% Create a datatip to show results
datatip(h);
  댓글 수: 1
Renan Deuter
Renan Deuter 2022년 1월 18일
It worked perfectly!
Thank you very much for the good explanation and the example

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by