is there any function similare to pixelinfo but for pcolor ?
    6 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
is there any function similare to pixelinfo but for pcolor ?
0 comentarios
Respuestas (1)
  Rahul
      
 el 24 de En. de 2025
        While there is no direct function which provides the functionality of 'impixelinfo' function for 'pcolor'. However, a similar functionlity can be achieved using by defining a 'hoverCallback' function to the 'WindowButtonMotionFcn' property. Here is an example:
[X, Y, Z] = peaks(25); % Taking some example data
h = pcolor(X, Y, Z);
% Setting up the figure to respond to mouse motion
set(gcf, 'WindowButtonMotionFcn', @(src, event) hoverCallback(src, event, X, Y, Z));
function hoverCallback(~, ~, X, Y, Z)
    % Get the current point in the axes
    ax = gca;
    cp = ax.CurrentPoint;
    x = cp(1,1);
    y = cp(1,2);
    % Find the closest data point
    [~, xi] = min(abs(X(1,:) - x));
    [~, yi] = min(abs(Y(:,1) - y));
    % Display the Z value at the closest point
    if xi > 0 && yi > 0 && xi <= size(Z, 2) && yi <= size(Z, 1)
        zValue = Z(yi, xi);
        title(ax, sprintf('X: %.2f, Y: %.2f, Z: %.2f', X(yi, xi), Y(yi, xi), zValue));
    end
end
The following MATLAB Answers can also be referred:
Refer to the following MathWorks documentations to know more:
'Create Callbacks for Graphic Objects': https://www.mathworks.com/help/matlab/creating_plots/create-callbacks-for-graphics-objects.html
Hope this helps! Thanks.
0 comentarios
Ver también
Categorías
				Más información sobre Graphics Performance en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

