Preserve Name of Indexed Variable for columns when creating a Table

조회 수: 16 (최근 30일)
TS
TS 2021년 3월 24일
댓글: leka0024 2023년 11월 22일
As title says i want to creat a table that contains different values.
If i write
T = table(Time,Data,Etc);
the names of the columns will be
Time Data Etc
BUT if i write
T = table(Time(1:50,:),Data(1:50,:),Etc);
the names of the columns will be
Val1 Val2 Val3
So my question is, how can i preserve the names of the variables when indexing them? I know there are some methods to do this by creating new variables with the indexed value or change the name of the columns with the properteries option. But this is an additional step i have to make and im lazy.

답변 (1개)

Geoff Hayes
Geoff Hayes 2021년 3월 24일
TS - you can set the variable names when you create the table
T = table(Time(1:50,:),Data(1:50,:),Etc(1:50,:), 'VariableNames', {'Time', 'Data', 'Etc'});
  댓글 수: 7
Walter Roberson
Walter Roberson 2023년 11월 22일
If Time(randi(height(Time),10,1) were to be passed in, then should the "name" that goes along be "Time(randi(height(Time),10,1)" or should it be "Time([61;80;6;13;49;40;77;61;46;6],1)" ? And what should be the corresponding name of the table variable that should be generated ?
leka0024
leka0024 2023년 11월 22일
Inputnames() should be able to get at a "string screenshot" of whatever was actually input.
As if the user was separately prompted to type in what they wanted each input argument to be, and whatever they typed in was saved as a string. That's plenty good enough. If you need the actual numbers of the indices, you can do that in the function and remake the string that gets displayed. You can't do anything now.
My context is a function that analyzes data and then plots results. It seems unreasonable to me to have to make a call like:
analyzeDataAndPlotResults(overallData(bestN,[4 5 7 8]),"overallData(bestN,[4 5 7 8])")
in order to have "overallData(bestN,[4 5 7 8])" displayed on the analysis figures.
The new (temp) array of the actual values of verallData(bestN,[4 5 7 8]) can continue to be labeled whatever they are labeled now. So long as inputnames can get at that "overallData(bestN,[4 5 7 8])".

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

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by