How to get the values of graphs interactively in a matlab GUI

2 次查看(过去 30 天)

I have this code which helps me to get t1,t2 manually and then get delt How to bring in a graph and then select points interactively to get delt

--- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
t1=get(handles.edit5,'string');
format long
t1=str2num(t1);
t2=get(handles.edit6,'string');
format long
t2=str2num(t2);
delt=(t2-t1);
set(handles.edit9,'string',delt);
  2 个评论
Geoff Hayes
Geoff Hayes 2018-4-23

Kaleesh - what happens when you use ginput?

 [x,y] = ginput(2); % since you want 2 points
 % now calculate the delta between the x or y 
 % (not sure which is your t)
Ramesh Bala
Ramesh Bala 2018-4-24
编辑:Ramesh Bala 2018-4-24
Danke Geoff for the reply. I actually used Gpts to get the X1,X2 as T1 and T2.
addpath 'C:\Users\Desktop\50-300\' I = imread('7,1.png');
I = imread('7,1.png');
image(I);figure(gcf);
[x] = getpts;
delt=(x(2,2)-x(2,1)); set(handles.edit9,'string',delt);
But,now the figure comes I select two points gets X values. Now I'm unable to substitute those X values to edit box ? Earlier the edit boxes were created just to get the values and then do the calculation.
Is there any way to subsitute the obtained X1,X2 values to those edit tabs
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
So how to use edit 5 to get X1 and edit 6 to get X2

请先登录,再进行评论。

采纳的回答

Geoff Hayes
Geoff Hayes 2018-4-25
Kaleesh - if you are just trying to update your edit text controls with the values that you have obtained using getpts then you could try
function some_callback(hObject, eventdata, handles)
I = imread('7,1.png');
image(I);figure(gcf);
[x] = getpts;
delt=(x(2,2)-x(2,1));
set(handles.edit9,'string',num2str(delt));
set(handles.edit5,'string',num2str(x(2,1)));
set(handles.edit6,'string',num2str(x(2,2)));
So just convert the number into a string using num2str.
  5 个评论
Geoff Hayes
Geoff Hayes 2018-4-26
Kaleesh - just create a new figure as
fHandle = figure;
then that figure becomes the current figure and so your image should be drawn to it.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by