MATLAB: Accessing Table from Workspace from Matlab Editor.

workspace gui matlab editor

Hello,
I have a created a GUI which gets data from different sources, apply some modifications on these tables. For some other calculations, I need to access these tables in order to modify them again for other calculations.
The first thing I did, is to create a listbox which will scan my workspace
vars = evalin('base','who'); set(handles.listbox32,'String',vars)
Then each time I will click on one of the variables, i will be able to transform the dataset, for example here, as a FINTS.
i have 2 tables in my ws : A and B but can j or K.
so my code is the following :
for i = 1:numel(who)
if get(handles.listbox32, 'value') == i % normally A will correspond to 1 and B to 2.
%Access the Table. and make a fints(table) tvar = evalin('base','who') TableName = char(tvar(i,1)) Dates = TableName(:,1) Data = TableName(:,2) fints(Dates,Data)
This is not working mainly because TableName is being considered as a string and hence no kind of relation with table A.
Do you know how to make the link with the first table in my workspace and calibrate it each time I click on any handles.listbox which will point to some other table….
Thank you very much
Davin.

Best Answer

Davin - any code that you add to your question can be formatted so that is a easier to read. Just highlight the code portions and press the {} Code button. So your last comment would become more like
tvar = evalin('base','who') ;
TableName = char(tvar(i,1));
Dates = TableName(:,1) ;
Data = TableName(:,2);
fints(Dates,Data);
Since your table is in the base workspace, and you get the table name via the list of variables returned by evalin, you could just re-use evalin to evaluate the command to return the first or second column of data from that table. Something like
Dates = evalin('base',[TableName '(:,1);']);
Data = evalin('base',[TableName '(:,2);']);
The above should work, but there could be alternatives without having to access information in the workspace. Why not just copy the two (or more) tables to the GUI, saving them as fields within the handles structure (if you are designing your GUI using GUIDE)? Is there a reason that these tables must remain in the workspace, outside of the GUI?