How to navigate on indexed table with user input

2 ビュー (過去 30 日間)
Usune Elizondo
Usune Elizondo 2021 年 9 月 24 日
コメント済み: Usune Elizondo 2021 年 9 月 27 日
Hello, I have an indexed object on the workspace.
I would like to ask the user for all of the inputs. Then it will create the path to the exact value located inside the tables I have indexed.
dat1.dat2.dat3.(var)
I want to ask the user tu input one by one all dat1 dat2 dat3 and var, and then show the value. Something like this, which is wrong:
dat1=input('dat1:','s');
dat2=input('dat2:','s');
dat3=input('dat3;','s');
var=input('var:','s);
solution=dat1.dat2.dat3('var')
Any ideas?
  1 件のコメント
Usune Elizondo
Usune Elizondo 2021 年 9 月 24 日
I think I have not explained myself properly.
I have some tables which are organized by indexing. So you can access with dot indexing to the different levels.
I would like to ask the user to give me the values of those levels until the variable they want to get the value of.
dat1.dat2.dat3(var)
so the user has to probide which dat1, which dat2, which dat3 and finally which var they want to visualize.
Thank you again

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

採用された回答

Siddharth Bhutiya
Siddharth Bhutiya 2021 年 9 月 24 日
You could use the t.(varName) syntax to do this. Here's a simple example
>> t = table(table(table([1;2;3],[4;5;6],'VariableNames',["V1","V2"]),'VariableNames',["TableVar"]))
t =
3×1 table
Var1
TableVar
_________
1×2 table
1×2 table
1×2 table
>> dat1 = "Var1";
>> dat2 = "TableVar";
>> dat3 = "V2";
>> t.(dat1).(dat2).(dat3)
ans =
4
5
6
% Which should be equivalent to doing the following
>> t.Var1.TableVar.V2
ans =
4
5
6
  1 件のコメント
Usune Elizondo
Usune Elizondo 2021 年 9 月 27 日
Thank you very much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by