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

추가 답변 (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