MATLAB: How to get the value of a variable from workspace using the editor from a gui

MATLABmatlab guiuitable

I'm creating a gui for a research project. The program that im creating uses a table and an axes to plot information. I'im trying to make it as simple as possible for anybody to use by using two push buttons: one for gathering the information from a ".txt" file to put into the table, and the other one to plot said info.
I am able to save the data of the .txt file into a variable but my question is…is it possible to get that value from that variable in the workspace into the table of the gui?
Thanks in advance 🙂

Best Answer

[txtname, txtpath] = uigetfile('*.txt', 'Select input file');
if isnumeric(txtname); return; end
filename = fullfile(txtpath, txtname);
data = dlmread(filename);
fig = gcf();
th = uicontrol('Parent', fig, 'Units', 'norm', 'Position', [0.05 .5 .9 .4]);
set(th, 'Data', data)
ax = axes('Parent', fig, 'Units', 'norm', 'Position', [0.05 0.05 .9 .4]);
plot(ax, data);