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

1 回表示 (過去 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 Center および File Exchange2-D and 3-D Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by