Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Scatter Plot?

Subject: Scatter Plot?

From: Nas

Date: 21 Jun, 2010 06:19:05

Message: 1 of 2

Hi,

I have data in the form of

x,y, class number, image.png

the first two are geographical coordinates, then I have a int value for class number and image.png is the path to an image file. I plot my data using scatter(x,y,10,class number) i.e. i color the points in the scatter plot by their class number.

Now my question is: everytime i click on a point in the scatter plot how can I get the associated image to pop up.

thanks in advance.

Subject: Scatter Plot?

From: Rodney Thomson

Date: 21 Jun, 2010 07:34:05

Message: 2 of 2

"Nas " <a.nasir@acfr.usyd.edu.au> wrote in message <hvn08p$b36$1@fred.mathworks.com>...
> Hi,
>
> I have data in the form of
>
> x,y, class number, image.png
>
> the first two are geographical coordinates, then I have a int value for class number and image.png is the path to an image file. I plot my data using scatter(x,y,10,class number) i.e. i color the points in the scatter plot by their class number.
>
> Now my question is: everytime i click on a point in the scatter plot how can I get the associated image to pop up.
>
> thanks in advance.

Quite simple with the use of callback events!

1) Create the callback code to load the image on the click. Note the callback methods will have 2 implicit parameters (src and event) that you must include. Anything after this can be custom parameters:

function loadImageInNewFig(src, event, class_name, filename)
    % Load image
    A = imread(filename);
    % plot in new figure
    figure;
    image(A)
    % put the class name in title (shows how we can use those parameters)
    title(sprintf('Class - %s', class_name));
end

2) When you plot, you assign a 'ButtonDownFcn' property which represents the function and associated parameters to call when that object is clicked:

filename = 'C:\decoded_ping_id.png';
figure;
p = plot(rand(4), '.');
set(p, 'ButtonDownFcn', @(src,event)loadImageInNewFig(src, event, 'test species', filename));
    
3) Thats it, click away!

Rod

--
http://iheartmatlab.blogspot.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us