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

3 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2017-8-2
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by