Hi,
lets say I have 3 variables with same length, a,b,c.
If I plot the data with `plot(a,b)`, I can see the values of a and b on the figure when over on a point.
Is there a way to display the value of c as well when I over through a point?

답변 (1개)

Walter Roberson
Walter Roberson 2023년 1월 14일

0 개 추천

Note that this can only be used for some kinds of plotting. For other kinds of plotting you would need to use datacursormode with a customized display function. datacursormode has the advantage that general computations can be done to create what is displayed, not just pre-computed values... but it is a bit of a nuisance to figure out which part of the graph you are pointed to when you use the function.

댓글 수: 4

michael
michael 2023년 1월 16일
편집: michael 2023년 1월 16일
The issue with datacursormode is that I can show only the values for x,y axes. I can't show any 3rd and 4th value (on 2D plot) which are some extra data relevant to the plot
Walter Roberson
Walter Roberson 2023년 1월 16일
편집: Walter Roberson 2023년 1월 16일
Return a cell array of character vectors, one per line. You can use any kind of calculation to determine what to put there.
The pain with datacursormode is that you might need to use the Position information to calculate the distance to objects in your graph to figure out what the user is pointing to.
I see though that an object with datatiptemplate is passed in, and that leads to possibilities that I have not explored
https://itecnote.com/tecnote/matlab-how-to-display-numbers-with-higher-precision-in-a-matlab-data-cursor/
michael
michael 2023년 1월 16일
Unfortunetly, I still don't understand what I have to do.
lets say I have 4 variables, a,b,c,d
I create a plot with plot(a,b);
I'd like that when passing with cursor on some point, there would be reference to all the 4 variables
Walter Roberson
Walter Roberson 2023년 1월 16일
You are using a rather old version of MATLAB. I am not sure if I have that installed anywhere.
The second parameter to the callback function has a field that permits you to access the current position being pointed at. You can calculate the distance between those coordinates and every point you plotted and find the minimum distance. That will tell you which plotted point you pointing at and allow you to figure out the index of that point within its line object. You can then use your knowledge of which line was being pointed to and the relative index in order to pull out appropriate associated information. You format all of the desired information as a cell array of character vectors and return it. Each cell entry will be displayed on its own line.
There might potentially be shorter ways; I would need to go back to a system that old and test.

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

카테고리

도움말 센터File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

제품

릴리스

R14SP2

태그

질문:

2023년 1월 14일

댓글:

2023년 1월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by