Preserve Name of Indexed Variable for columns when creating a Table
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Geoff Hayes
am 24 Mär. 2021
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 Kommentare
Walter Roberson
am 22 Nov. 2023
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
am 22 Nov. 2023
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])".
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!