How to take value of X and Y from plot put it in Text Edit field using button press in Matlab App?

Hello,
I want to extract value of X and Y from plot to Text edit field like I have attached image of my plot, Now on the X Axis I want only x value 5.1159m/s into my text field while press the button and on the Y Axis I want two value 1.01864 and 51.2092 into my text edit field. So, Could anyone help me, How to write code for this?

Answers (1)

Hi,
I have not tried within apps, but the getDataTips function from File Exchange may help you to extract the data from the data tips.
It is not clear to me how you decide what values should go into what edit field, but I suppose that is the easier task.
Best wishes,
Harald

8 Comments

Thanks @Harald
I have tried it but it does not work on Matlab App designer. Also I have tried data cursor mode it works on normal figure but not working in UIAxes(Matlab app 2022b). here is my code, if you know anything about it then it will be very helpful.
function ButtonPushed(app, event)
dcm = datacursormode(app.UIAxes2, 'on');
% Get information about the selected data points
info = getCursorInfo(dcm);
% Extract Y values from the selected data points
app.Von1EditField_ACX.Value = info(3).Position(2);
app.Bis1EditField_ACX.Value = info(2).Position(2);
app.Vmax_1EditField_DVX.Value = info(1).Position(1);
end
Actually I want to fill 3 text edit field.
Hi Dhaval,
if possible, please provide an example app.
Also I suppose that you are getting error messages? If so, please post the error message.
Best wishes,
Harald
Hello Herald,
I am getting this error:
Error using datacursormode
Do not specify an output argument with these input arguments.
Error in Test_tool/ButtonPushed (line 5052)
dcm = datacursormode(app.UIAxes2, 'on');
I have used app.UIAxes2 becuase my UIAxes is in the second Tab (My tab name is AC vs DV) not in the Main tab. So, is it create any problem or not?
Thanks and regards,
Dhaval
Hi Dhaval,
The error message indicates that you are using an unsupported syntax of datacursormode. The following may work:
datacursormode(app.UIAxes2, 'on');
dcm = datacursormode;
There might be a simpler way, using the File Exchange function I have suggested.
I have created a little app that extracts data tips and displays them in a table. Looks good to me:
For further assistance, please provide an example app. It is just difficult to troubleshoot when only seeing a small bit of your application.
Best wishes,
Harald
Hello Herald,
I have used function like you have mentioned but now I got this error:
Error using datacursormode
Invalid figure handle
Error in Test_tool/ButtonPushed (line 5052)
datacursormode(app.UIAxes2, 'on');
This is my aplication's small part:
You can see that I am using UIAxes on second tab. Also, There are 5 editfield but I want to fillout first 2 and last one. In the first two, I need only Y vlaue, which is selected near Y Axis (0.56 and 79.31) and In the last one I need only X value (5.1). for that I am using this code:
datacursormode(app.UIAxes2, 'on');
dcm = datacursormode;
% Get information about the selected data points
info = getCursorInfo(dcm);
% Extract Y values from the selected data points
y1_value = info(3).Position(2);
y2_value = info(2).Position(2);
vmax_vlaue = info(1).Position(1);
von1 = sprintf('%.0f', y1_value); % Format to one decimal place
bis1 = sprintf('%.0f', y2_value);
Vmax_1 = sprintf('%.1f', vmax_vlaue);
app.Von1EditField_ACX.Value = str2double(von1);
app.Bis1EditField_ACX.Value = str2double(bis1);
app.Vmax_1EditField_DVX.Value = str2double(Vmax_1);
Hi,
the code you are sharing is not using that function, and the code is not sufficient to reproduce the problem.
It seems like your axes is not called UIAxes2. Check the component browser within App Designer to verify that this is the correct name.
Best wishes,
Harald
Hi,
I have checked it and It is same name as in component browser. So, I think that is not a problem.
with regards
Dhaval
Hi,
unfortunately, this is the only suggestion I can make from the code and error provided.
To further investigate for you, I would need a reproducible example. You would not have to share the full app, but enough to run the app and encounter the error message.
Best wishes,
Harald

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2022b

Asked:

on 25 Aug 2023

Commented:

on 4 Sep 2023

Community Treasure Hunt

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

Start Hunting!