我正在尝试用matlab做GUI,用户输入点和它们之间的连接。他还输入了地图照片(png图像)和轴的比例(ax x将从0到比例)。 最后(在他输入所有输入之后)我想向用户显示包含所有节点和连接的图像。
我有5个matlab文件 - screen1.m,screen2.m,screen3.m,screen4.m,globalParams.m
在globalParams我有全局参数,所以我可以使用它们从屏幕GUI到屏幕GUI。在screen1中,用户输入节点数(例如5),并且他也进入地图。当他按下Next按钮时,回调函数会调用“screen2();
”。在screen2.m中,用户输入(x,y)coordiante,当他按下Next按钮时,回调函数调用“screen3();
”。
在screen3中,用户更新所有节点之间的所有连接。完成后按“完成”按钮,回调函数调用“screen4
”。在screen4中我添加了GUI轴,然后我做了“imshow
”..
但是我想要做真实的东西是改变轴是从0到规模(而不是0比1),我想也把图像(我用imshow做到了),最后和我想要在图像上放置的最重要的东西是节点和它们之间的线(如果用户在节点i和节点j之间添加连接,那么在图像中它们将是它们之间的一条线。也许是为了放置线和节点使用不同的颜色,以便我们可以区分线条和节点
在screen4我们有:。的 xNodes 和 yNodes - 2个阵列对于节点 “x” 和 “y” 的轴((xNodes(1),yNodes(1)为node1地方)。另外,我们有比例和 fullPathName 作为图像名。我们还hopsMatrix它2D基于阵列如果hopsMatrix(I,J)= 1有我之间的连接到j。
一些代码:
在screen1中,上传图片和numOfNodes和scale:
% --- 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);
答案 0 :(得分:0)
这是某人给我的解决方案..我会分享它
% --- 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;
imshow(fullPathName);
global xNodes;
global yNodes;
global scale;
global hopsMatrix;
x_original=get(handles.axes1,'xlim');
y_original=get(handles.axes1,'ylim');
min_lim=min(x_original(2),y_original(2));
max_lim=max(x_original(1),y_original(1));
xlim([max_lim,min_lim])
ylim([max_lim,min_lim])
dist=min_lim-max_lim;
set(handles.axes1)
hold on
plot((xNodes(:,1))*dist/scale+x_original(1),min_lim+y_original(1)-(yNodes(:,1))*dist/scale,'rx','markersize',8,'linewidth',2)
[row,col] = find(hopsMatrix);
for i=1:length(row)
plot((xNodes([row(i),1;col(i),1]))*dist/scale+x_original(1),min_lim+y_original(1)-(yNodes([row(i),1;col(i),1]))*dist/scale,'k','linewidth',2)
end