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

2 visualizaciones (últimos 30 días)

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 comentarios
Geoff Hayes
Geoff Hayes el 23 de Abr. de 2018

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 el 24 de Abr. de 2018
Editada: Ramesh Bala el 24 de Abr. de 2018
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

Iniciar sesión para comentar.

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 25 de Abr. de 2018
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 comentarios
Geoff Hayes
Geoff Hayes el 26 de Abr. de 2018
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 el 27 de Abr. de 2018
Sehr Gut !! :) Thanks for the valuable comments!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by