When attempting to assign VariableNames to table columns when using array2table I am getting the error:
Error using array2table (line 62)
The VariableNames property must be a cell
array, with each element containing one
nonempty string.
This error however only occurs when using a cell-array constructed using strcat or sprintf, for example:
for p=1:length(b)
string{p,:} = {strcat(a,num2str(b(p)))};
end
string =
{1x1 cell}
{1x1 cell}
{1x1 cell}
{1x1 cell}
Whereas, assigning the VariableNames directly:
T = array2table(ncoIED,'VariableNames',{'A' 'B' 'C' 'D'});
Works as intended.
This seems to be down to the way the strings are stored in the cell-array - each string is surrounded by ' ' whereas a = {'A' 'B' 'C' 'D'}; does not add this.
I need to be able to dynamically create string names by concatenating multiple variables - is there a way to do this that will be compatible with the VariableNames parameter?
For example, if I have two cell arrays and a numerical matrix, in these forms:
g =
TT
uID =
3
4
5
10
s =
'CC'
'NN'
'AA'
I want to create 12 unique strings following these rules:
TT3CC
TT3NN
TT3AA
TT4CC
TT4NN
TT4AA
TT5CC
TT5NN
TT5AA
TT10CC
TT10NN
TT10AA
That can be used to label a table.
EDIT
Second set of naming rules:
TT3NN
TT4NN
TT5NN
TT10NN
TT3CC
TT4CC
TT5CC
TT10CC
TT3AA
TT4AA
TT5AA
TT10AA