【问题标题】:How can I pass values between call_backs in Matlab GUI如何在 Matlab GUI 中的 call_backs 之间传递值
【发布时间】:2014-11-06 11:05:03
【问题描述】:

我是 Matlab 的新手。现在的任务是在 GUI 中显示标题并在脚本运行时不断更新标题。

我创建了一个名为 Interface 的 GUI,所以 Main 中的脚本是

Interface(title);

在图形界面中

function Interface_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 Interface (see VARARGIN)

% Choose default command line output for Interface
handles.output = hObject;
handles.title = varargin{1};
% Update handles structure
guidata(hObject, handles);

我将标题传递给handles.title。

在静态文本的回调函数中:

title =get( handles.title,'Value');
set(handles.text1,'String',title');

它一直给我错误消息说我正在阅读“尝试引用非结构数组的字段。”

感谢您的帮助

【问题讨论】:

  • set(handles.text1,'String',title'); 在title 之后有一个' 不属于那里。

标签: matlab user-interface


【解决方案1】:

我认为你只需要:

set(handles.text1,'String',handles.title); % assumes the title input (and therefore handles.title) is a string
guidata(hObject,handles);

只需确保将静态文本的回调函数作为输入传递 handles。另外,你没有说 handles.text1 是如何定义的,我假设你在尝试设置它的 String 属性之前已经定义了它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-10
    • 1970-01-01
    • 1970-01-01
    • 2013-04-08
    相关资源
    最近更新 更多