How to navigate on indexed table with user input

1 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by