I am running something like this:
table = readtable(path,'ReadVariableNames',true);
In the .csv file all of the cells of the first row contain string identifiers like '99BM'
, '105CL'
, etc. Everything starts with a number. The command above gives a table with variable names like 'x99BM'
, 'x105CL'
, etc.
Is it possible to get rid of this 'x'
? I need to compare these identifiers with a column of another table that is clear of this 'x'
.
No, table variable names can't start with a number since they follow the same naming conventions as normal variables. The 'x'
is automatically added by readtable
to create a valid name. You should have noticed this warning when calling readtable
:
Warning: Variable names were modified to make them valid MATLAB identifiers.
The original names are saved in the VariableDescriptions property.
So, you can't get rid of the 'x'
within the table. But, if you need to do any comparisons, you can do them against the original values saved in the VariableDescriptions
property, which will have this format:
>> T.Properties.VariableDescriptions
ans =
1×2 cell array
'Original column heading: '99BM'' 'Original column heading: '105CL''
You can parse these with a regular expression, for example:
originalNames = regexp(T.Properties.VariableDescriptions, '''(.+)''', 'tokens', 'once');
originalNames = vertcat(originalNames{:});
originalNames =
2×1 cell array
'99BM'
'105CL'
And then use these in any string comparisons you need to do.