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

조회 수: 2 (최근 30일)
Ramesh Bala
Ramesh Bala 2018년 4월 19일
댓글: Ramesh Bala 2018년 4월 27일

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.
Ramesh Bala
Ramesh Bala 2018년 4월 27일
Sehr Gut !! :) Thanks for the valuable comments!

댓글을 달려면 로그인하십시오.

추가 답변 (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