Azzera filtri
Azzera filtri

How to rename TABLE column by the combination of Character and number?

4 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Star Strider
Star Strider il 2 Ago 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 Commenti

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by