我正在嘗試在matlab中做GUI,用戶輸入點和它們之間的連接。他還輸入地圖照片(png圖像)和座標軸(ax x將從0縮放)。 最後(他輸入所有輸入之後)我想向用戶顯示包含所有節點和連接的圖像。matlab gui - 在圖像上繪製點和線
我有5個MATLAB文件 - screen1.m,screen2.m,screen3.m,screen4.m,globalParams.m
在globalParams中我有全球PARAMS,所以我可以使用他們從屏幕GUI篩選GUI 。在屏幕1中,用戶輸入節點的數量(例如5),並且他也輸入地圖。當他按Next按鈕時,回調函數調用「screen2();
」。在screen2.m中,用戶輸入(x,y)座標,當他按Next按鈕時,回調函數調用「screen3();
」。在screen3中用戶更新所有節點之間的所有連接。完成後按下完成按鈕,回調函數調用「screen4
」。在screen4中,我添加了GUI軸,在那裏我做了「imshow
」.. 但我想要做的事情是將軸從0改爲scale(而不是0到1),我也想要放置圖像(我用imshow做了這個),我想要放在圖像上的最後一個也是最重要的是它們之間的節點和線(如果用戶在節點i和節點j之間添加了連接,所以在圖像將是它們之間的線也許把線和所述節點與不同勢的顏色,以便我們可以區分 在screen4我們有線和節點):xNodes和yNodes - 2陣列用於在節點「× (xNodes(1),yNodes(1)是node1的地方),我們還有Scale和fullPathName爲圖像名稱。我們還有hopsMatrix它是2D數組 - 如果hopsMatrix(i,j)= 1,則i到j之間存在連接。
一些代碼:
在屏蔽1,上傳圖像和numOfNodes和規模:
% --- 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)
global fullPathName;
[fileName pathName] = uigetfile({'*.png'},'File Selector');
fullPathName = strcat(pathName, fileName);
imshow(fullPathName);
% --- 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)
global numOfNodes;
global scale;
scale = str2num(get(handles.edit1, 'string'));
numOfNodes = str2num(get(handles.edit2, 'string'));
在screen4,在那裏我有所有的投入,我希望把節點地圖(我不知道該怎麼做,所以現在這是代碼):
% --- Executes just before screen4 is made visible.
function screen4_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to screen4 (see VARARGIN)
global fullPathName;
global xNodes;
global yNodes;
global scale;
global hopsMatrix;
img = imread(fullPathName);
imshow(fullPathName);