Preserve Name of Indexed Variable for columns when creating a Table
12 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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
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
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 Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!