How to navigate on indexed table with user input

2 Ansichten (letzte 30 Tage)
Usune Elizondo
Usune Elizondo am 24 Sep. 2021
Kommentiert: Usune Elizondo am 27 Sep. 2021
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 Kommentar
Usune Elizondo
Usune Elizondo am 24 Sep. 2021
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Siddharth Bhutiya
Siddharth Bhutiya am 24 Sep. 2021
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

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by