Accessing Table from Workspace from Matlab Editor.

6 ビュー (過去 30 日間)
Davin
Davin 2014 年 10 月 2 日
コメント済み: Davin 2014 年 10 月 2 日
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.
  1 件のコメント
Davin
Davin 2014 年 10 月 2 日
tvar = evalin('base','who') ;
TableName = char(tvar(i,1));
Dates = TableName(:,1) ;
Data = TableName(:,2);
fints(Dates,Data);

サインインしてコメントする。

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 10 月 2 日
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?
  1 件のコメント
Davin
Davin 2014 年 10 月 2 日
Thanks very much Geoff, I managed to find a way to do in the mean time. I did a function to fetch the values in the handles. string then used the evalin as u mentionned, the tricky thing was the syntax -- >
[TableName '(:,1);'].
I still have to learn the different ways to write these commands.There is no real reason for the tables to appear in the workspace.I will look into the way you mentionned, I am sure its more optimized.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by