简体   繁体   English

如何从Matlab工作区到gui检索指向编辑文本的数据点?

[英]How to retrieve data point into edit text from matlab workspace to gui?

I have 8x1 cell matrix in my matlab workspace called textdata. 我的matlab工作区中有8x1的单元矩阵,称为textdata。 It contains tickers in each row. 它在每一行中包含代码。 How do I use pushbutton and edit1_Callbacks to program a this basic data point retrieval operaton (what is the code and where do I type it? No fancy stuff, just want to know how to import the textdata into gui and with the push of a buttun retrieve the first ticker into the edit text box (1 data point from first row of textdata)? 我如何使用pushbutton和edit1_Callbacks对这个基本数据点检索edit1_Callbacks进行编程(代码是什么,我应该在哪里键入它?没有花哨的东西,只想知道如何将文本数据导入gui并按下buttun检索到编辑文本框中的第一个代码(文本数据第一行中的1个数据点)?

You can use the Matlab function evalin to retrieve a workspace variable from your GUI. 您可以使用Matlab函数evalin从GUI中检索工作区变量。

The following example GUI demonstrates this, you can probably expand from this starting point: 以下示例GUI演示了这一点,您可能可以从这个起点开始扩展:

% GUI
function so_wsgui
figure('units','normalized',...
    'position',[0.15 0.15 0.7 0.7],...
    'color',[1 1 1]*0.5,...
    'numbertitle','off',...
    'menubar','none',...
    'toolbar','none',...
    'tag','figure');
data=guihandles(gcf);
uicontrol('parent',data.figure,...
    'style','pushbutton',...
    'string','Import',...
    'units','normalized',...
    'position',[0.1 0.85 0.8 0.05],...
    'callback',@import_callback);
uicontrol('parent',data.figure,...
    'style','edit',...
    'horizontalalignment','center',...
    'backgroundcolor',[1 1 1],...
    'units','normalized',...
    'position',[0.1 0.5 0.8 0.05],...
    'tag','text');
data=guihandles(gcf);
guidata(gcf,data);
end
% Callbacks
function import_callback(obj,event) %#ok
data=guidata(gcbf);
try
    wsvar=evalin('base','textdata');
    set(data.text,'string',wsvar{1});
catch exception
    set(data.text,'string',['Error: ' exception.identifier]);
end
end

However you have to be careful with this because nothing garantees you that the variable exists or that it is a cell array, so you must be cautious. 但是,您必须注意这一点,因为没有任何东西可以保证您知道该变量存在或它是一个单元格数组,因此您必须谨慎。 This is not really the usual way to pass data to a GUI. 这实际上不是将数据传递到GUI的通常方法。

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

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