How to create a table name using a string variable?

Hi,
How can I use a string variable for a table name?
eg.:
-----------------------------
T = 'ThisShouldBeMyTableName';
VariableNames = {'StartCash','EndDate'};
T = table(input_values.StartCash, input_values.EndDate, 'VariableNames',VariableNames);
-----------------------------
The table which is create should be named "ThisShouldBeMyTableName" not "T".
Thank you

댓글 수: 3

Stephen23
Stephen23 2019년 3월 8일
편집: Stephen23 2019년 3월 8일
Dynamically accessing variables names is one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug. Read this to know some of the reasons why:
Use indexing. Indexing is simple, neat, and very efficient. Unlike what you are trying to do.
@stephen Can you please elaborate what you mean by indexing? How exactly do I use this indexing?
Mustafa Calcuttawala: please read the material at the link that Stephen posted. It shows a number of different possibilities.

댓글을 달려면 로그인하십시오.

 채택된 답변

Gabor
Gabor 2019년 3월 4일

1 개 추천

I guess I will just use a cell which I will be store the the variable for the "name that should be" and the table itself too...
Thank you

댓글 수: 1

Or you could create a struct array with one field that contains your table and name that field using either the struct function or dynamic field names.
thefield = 'snowstorm';
data = magic(4);
structOfTables = struct(thefield, data)
structOfTables2.(thefield) = data

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

제품

릴리스

R2017a

질문:

2019년 3월 4일

댓글:

2020년 6월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by