Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6975735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:24:24+00:00 2026-05-27T17:24:24+00:00

I have to analyse a lot of data, to do this I defined several

  • 0

I have to analyse a lot of data, to do this I defined several classifiers of the data. I want to make something dat if I click with the data cursor on a point on the graph it stores the point and subtracts it from the next. So that I can find the peak to peak heigth of a sine. Like y2-y1.

I found the following code to extract the points. Only it’s a function that is called every time and has no memory.

function out = getIndex(obj,event_obj,X,Y)
pos = event_obj.Position;
d1 = (X-pos(1)).^2 + (Y-pos(2)).^2;
[ignore index] = min(d1);
out = {sprintf('X: %f',pos(1)),...
sprintf('Y: %f',pos(2)),...
sprintf('Index: %d',index)};
% disp(pos(1))
% pos(1)
pos(2)
save pos.mat pos

In Matlab you can test with:

X = 1:10;
Y = rand(1,10);
plot(X, Y)

You can apply the above function to be used with the datacursormode
using:

dcm = datacursormode(gcf);
set(dcm, 'UpdateFcn', @(x,y)getIndex(x,y,X,Y))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:24:25+00:00Added an answer on May 27, 2026 at 5:24 pm

    I recommend using another way in here. Instead of setting the callback for data cursor, set the callback directly for the plot.
    Extract the (X,Y) by querying the axes ‘CurrentPoint’.

    function so2()
    figure();
    a = axes();
    x = -10:0.01:10;
    sx = sin(x);
    h = plot(x,sx);
    set(h,’ButtonDownFcn’,{@Click_CallBack a});

    end

    function Click_CallBack(h,e,a)
    point = get(a,’CurrentPoint’);
    x = point(1);
    y = point(4);
    fprintf(1,’X,Y = %.2f,%.2f\n’,x,y);
    end

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used a generalized additive model to analyse some data and now wish
I work a lot with nested data structures, and many times I have to
I have been playing around with using graphs to analyze big data. Its been
I have installed sonar and it works on http://localhost:9000 When I want to analyze
Whilst I don't have no ANALYSE issues with my iPhone code, when I run
I have come across this problem in a calculation I do in my code,
I have 5 large XML files which I am keen to analyse. All of
I have to analyze a lot of XML files in my current project. I
I have some code I inherited which has a lot of warnings that I
A lot of services send your browser to another url when you click a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.