How to rename TABLE column by the combination of Character and number?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
balandong
le 2 Août 2017
Commenté : Star Strider
le 2 Août 2017
Dear all, pertaining of the above subject. I have the following code
c=1
for threshold = 0.5:0.01:0.6
for i =1:2
Table (c) = SomeFunction
end
% See line A
Table.Properties.VariableNames{c} = NewName
c=c+1
end
To have a new column name after each iteration of the threshold loop, I plan to rename the column name, for example, the column 1 and 2 is threshold_0_5 and threshold_0_51. The reason why threshold_0_5 and threshold_0_5 1 because MATLAB prohibit naming the column as threshold_0.5 & threshold_0.5.
By looking at the other thread,
possible conversion was
Data = strrep(threshold , '.', '_');
NewName = strcat ('threshold ',Data)
OR
NewName = strcat('Th',num2str(threshold)),
However, I got an error. May I know where did I do wrong?
Thanks in advance
0 commentaires
Réponse acceptée
Star Strider
le 2 Août 2017
I am not certain what result you want. All table variable names have to be valid MATLAB variable names, so decimal points are not permitted.
Try this:
threshold = 0.5:0.01:0.6;
NamesVct = sprintf('Th_%2.0f\n',threshold*100);
NewName = regexp(NamesVct, '\n', 'split');
NewName = NewName(1:end-1);
The last line is necessary because the regexp call produces an empty cell at the end.
4 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!