Datacursor to show Z axis String Info with Precise X axis information

Hi, I am trying to show the Z axis string info when I click the cursor on the plot (3D).
But the problem is that, when I have just a normal (default) datacursor function, it shows the Z-axis string info as it is shown below.
But I had to change the function to show the precise time information which then caused the Z data to hide the string info and shows the actual value info.
formattedValue = [valueFormat num2str(value,10) removeValueFormat];
Now the function shows that the precise time information but the Z value doesn't show the string info.
I tried to change the Z information within the data cursor to show the string info
% If there is a z value, display it:
if length(pos) > 2
valueFormat = ' \color[rgb]{0 0.6 1}\bf';
removeValueFormat = '\color[rgb]{.25 .25 .25}\rm';
tickLabel = event_obj.Target.Parent.ZTickLabel(pos(3));
output_txt{end+1} = ['Z', valueFormat tickLabel{3} removeValueFormat];
% output_txt{end+1} = ['Z',formatValue(pos(3),event_obj)];
end
It shows that this is invalid.
Anyone has any idea what I should be doing?
Thanks!

 Respuesta aceptada

tickLabel is a scalar cell array, so don't index it with 3. Use 1 instead:
output_txt{end+1} = ['Z', valueFormat tickLabel{1} removeValueFormat];

6 comentarios

I changed the ticklabel to {1} but it still gave the me same error. :(
I feel like it isn't taking the label but taking the original double format data from somewhere...?
Please share enough code and data for me to run and try to reproduce the problem.
Alternatively, you can put a breakpoint in your data tip update function and inspect the variable values (or remove semicolons so the values used are shown in the command window); make sure they are as you expect.
Hi, sorry for the delay, I made a sample file that could do the job but still has the same issue.
No problem. Thank you for the files.
Unfortunately, I don't have the Vehicle Network Toolbox, so I am unable to run the .mlapp file.
However, I did reproduce the problem using a simple plot
figure
plot3(1:10,1:10,1:10)
dcm_obj = datacursormode(gcf());
set(dcm_obj, 'UpdateFcn', @displayHighPrecision)
When that plot is created, the z-axis has 6 tick labels {'0','2','4','6','8','10'}. Now, displayHighPrecision wants to access the zticklabel at index pos(3), which is the z-coordinate. For instance if pos(3) is 7, you'll get an error trying to access the 7th zticklabel because there are only 6. Even if there is no error thrown, the logic is incorrect because the zticklabels don't match with the z values, i.e., not every point from z=1 to 10 has a ztick. This is probably the same problem that's happening in your code.
Is there a reason you want to use the zticklabels instead of just the z value, pos(3)? If so, you need to adjust your code to make sure that there's a tick for each point in the plotted line.
Sorry that (3) was not intended since I was trying to figure out what was wrong with my code. After awhile, I found the problem!
My data was generated as a category tab not a Zticklabel for some reason.
Thanks for looking into this problem but it was a simple mistake that I wasn't aware of.
Thank you!
Voss
Voss el 26 de Mzo. de 2024
Editada: Voss el 26 de Mzo. de 2024
You're welcome! Glad you got it sorted out.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2023a

Preguntada:

Min
el 21 de Mzo. de 2024

Editada:

el 26 de Mzo. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by