简体   繁体   English

如何将数据从功能输出到matlab到功能GUI.m

[英]how to send data from a function out GUI matlab to function GUI.m

How can I pass values (x_locate, y_locate) for a static text in my GUI? 如何在GUI中为静态文本传递值(x_locate,y_locate)? Because the function is out functions generated by the GUI. 由于该功能是由GUI生成的功能。 I'm not achieving to configure the set() function. 我没有实现配置set()函数。

I believe it is using handles, but I've tried everything and failed. 我相信它使用的是句柄,但我尝试了所有操作并失败了。

to simplify I rewrote the code: ![enter image description here][1] 为简化起见,我重写了代码:![在此处输入图片描述] [1]

The "Locations.fig" have: 1 axes, 1 pushbutton and 2 static text. “ Locations.fig”具有:1个轴,1个按钮和2个静态文本。

ctrl+C CTRL + C

function varargout = Locations(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Locations_OpeningFcn, ...
                   'gui_OutputFcn',  @Locations_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end

function Locations_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);

function varargout = Locations_OutputFcn(hObject, eventdata, handles) 
varargout{1} = handles.output;

function pushbutton1_Callback(hObject, eventdata, handles)

cla(handles.axes1,'reset');
axes(handles.axes1);

image = imread('eight.tif');
im = imagesc(image);

set(im,'ButtonDownFcn', @clique);

function clique (gcbo,eventdata,handles)

pos = get(gca, 'currentpoint');

x_locate = round(pos(1))
y_locate = round(pos(3))  % until here working!!!

set(handles.text1, 'string', ['x loc:' num2str(x_locate)]); %don´t working
set(handles.text2, 'string', ['y loc:' num2str(y_locate)]); %don´t working

ButtonDownFcn设置为:

set(im, 'ButtonDownFcn', @(src,evt)clique(src,evt,handles))

Only callbacks set through GUIDE (or some other custom means) receive the extra handles argument. 仅通过GUIDE(或某些其他自定义方式)设置的回调会收到额外的handles参数。 Otherwise, you'll need to retrieve the handles structure manually within the clique function: 否则,您将需要在clique函数中手动检索handles结构

handles = guidata(<object>);

The question of what <object> is depends on your GUI setup. <object>是什么的问题取决于您的GUI设置。 If im is a child of the GUI figure, then gcbo 1 will do. 如果im是GUI图形的子级,则gcbo 1gcbo If it's in a separate figure, then you'll need to get a handle to the GUI figure. 如果在单独的图中,那么您需要获取GUI图的句柄。 Using findobj to either enumerate all figures or search for some specific property of your GUI figure is the straightforward way to do it. 使用findobj枚举所有图形或搜索GUI图形的某些特定属性是执行此操作的直接方法。

For example, all Handle Graphics objects have a 'Tag' property that you are free to use, which would be helpful in this case. 例如,所有Handle Graphics对象都具有一个'Tag'属性,您可以自由使用它,在这种情况下将很有用。 In GUIDE, set the Tag property on your GUI figure to 'my GUI' , then you can retrieve the data from anywhere like so: 在GUIDE中,将GUI图形上的Tag属性设置为'my GUI' ,然后可以从任何地方检索数据,如下所示:

hfig = findobj('Tag','my GUI');
handles = guidata(hfig);

[1] Incidentally, giving variables the same name as built-in functions isn't a great idea [1]顺带一提,给变量与内置函数同名不是一个好主意

The Notlikethat resolved the problem! Notlikethat解决了问题! Thanks!!! 谢谢!!!

so: 所以:

x_locate = round(pos(1));
y_locate = round(pos(3));  % until here working!!!

hfig1 = findobj('Tag','text1');
handles = guidata(hfig1);
hfig2 = findobj('tag','text2');
handles = guidata(hfig2);

set(handles.text1, 'string', ['x loc:' num2str(x_locate)]);
set(handles.text2, 'string', ['y loc:' num2str(y_locate)]);

finalized 敲定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM