MATLAB Answers

0

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

Kaleesh Bala さんによって質問されました 2018 年 4 月 19 日
最新アクティビティ Kaleesh 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
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)
Kaleesh 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

サインイン to comment.

製品

1 件の回答

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 件のコメント

Kaleesh Bala 2018 年 4 月 26 日
Haello Geoff
Could you please kindly elaborate how to call a new figure before image?
Also I have modified mine to uiopen -which helps to browse for the figure and then select it ,won't work for png,tiff etc except .m files
function some_callback(hObject, eventdata, handles)
uiopen
zoom on;
pause() % you can zoom with your mouse and when your image is okay, you press any key'
zoom off; % to escape the zoom mode
pan off;
[x] = ginput(2)
delt=(x(2,2)-x(2,1));
fprintf('x2 = %f\n', x(2,2));
fprintf('x1 = %f\n', x(2,1));
zoom out; % go to the original size of your image
set(handles.edit9,'string',delt);
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.
Kaleesh Bala 2018 年 4 月 27 日
Sehr Gut !! :) Thanks for the valuable comments!

サインイン to comment.



Translated by