How to rename TABLE column by the combination of Character and number?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
balandong
am 2 Aug. 2017
Kommentiert: Star Strider
am 2 Aug. 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 Kommentare
Akzeptierte Antwort
Star Strider
am 2 Aug. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings 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!