簡體   English   中英

在Matlab中,如何創建一個GUI來與3個現有的m文件交互?

[英]In Matlab, how do I create a GUI to interface with 3 existing m files?

嗨,我正在嘗試創建一個GUI以鏈接到我的3 m文件。

1)findcontrolpoints.m 2)morph.m 3)morphvideo.m

在1)中,我需要獲得用戶輸入的點數。 輸入將在GUI中輸入,然后希望將變量傳遞到findcontrolpoints.m文件進行處理。 這將通過按下按鈕1來完成。 有什么辦法嗎?

function inputpoints_Callback(hObject, eventdata, handles)
% hObject    handle to inputpoints (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 inputpoints as text
%        str2double(get(hObject,'String')) returns contents of inputpoints as a double
input = str2num(get(hObject, 'String'));

if (isempty(input))
    set(hObject, 'String', '50')
end
guidata(hObject, handles);


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% hMainGui = getappdata(0, 'hMainGui');

% fileName = uigetfile('*.jpg');
points = get(handles.inputpoints,'String');

findfeaturepoint(points);

這樣的事情對您有用嗎? 我只是重復使用了另一個項目中的舊版GUI,因此您幾乎可以擺脫所有選項,並且仍然可以使用。

function interface
% Main figure
figure('units','normalized',...
    'position',[0.25 0.25 0.5 0.5],...
    'color',[1 1 1]*0.5,...
    'numbertitle','off',...
    'name','Interface',...
    'menubar','none',...
    'toolbar','none',...
    'tag','main');
% Data structure
data=guihandles(gcf);
% Input field
uicontrol('parent',data.main,...
    'style','text',...
    'string','Number of points',...
    'horizontalalignment','center',...
    'backgroundcolor',[1 1 1]*0.5,...
    'units','normalized',...
    'position',[0.4 0.7 0.2 0.1]);
uicontrol('parent',data.main,...
    'style','edit',...
    'horizontalalignment','center',...
    'string','0',...
    'backgroundcolor',[1 1 1],...
    'units','normalized',...
    'enable','on',...
    'position',[0.4 0.6 0.2 0.1],...
    'tag','input');
% Submit
uicontrol('parent',data.main,...
    'style','pushbutton',...
    'string','Submit',...
    'units','normalized',...
    'enable','on',...
    'position',[0.4 0.45 0.2 0.1],...
    'tag','submit',...
    'callback',@submit);
% Data structure
data=guihandles(gcf);
% Program parameters
data.default=50;
% ... %
guidata(gcf,data);
end
% Callbacks
function submit(obj,event) %#ok
% Data structure
data=guidata(gcbf);
input=get(data.input,'string');
% Input validation
% ... %
% Functions call
% ... %
guidata(gcbf,data);
end

對輸入進行評估后,只需從回調中調用三個函數即可。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM