Table header - possible to use special characters?

조회 수: 99(최근 30일)
Morten Jensen
Morten Jensen 2014년 11월 14일
댓글: Guillaume 2014년 11월 14일
I have constructed a table with data from a struct and now wish to add custom headers to the columns before exporting the table. I found the following command:
T.Properties.VariableNames{'OldHeader'} = 'NewHeader';
This command however does not allow me to use spaces or special characters for my headers. My table contains the output from processed lab data and I wish to have headers like this:
"Vol. [mL]" and "Conc. [wt%]"
Is this in any way possible?


Andrew Reibold
Andrew Reibold 2014년 11월 14일
I don't know if it actually works: Try using sprintf to print what text you want
  댓글 수: 2
Andrew Reibold
Andrew Reibold 2014년 11월 14일
So I had a spare second and just tried to establish "Vol mL" as a variable name not even include the special characters, and it says it was not an allowable variable name (Just for the space!)
I then tried to establish just "Vol[mL]" and was denied as well (Just for a special character!)
What a pain! I see what your problem is! My solution will not work and you will probably need help from one of the nerds (A term of endearment) on here that know how to alter the underlying Java if possible.
If you are able to avoid tables and use matrices, I would recommend it after seeing how inflexible they can be.

댓글을 달려면 로그인하십시오.

Guillaume 2014년 11월 14일
As detailed in the documentation of table You can only use valid Matlab variable names for your table variable names. It can only contain letters, numbers or underscore. One would assume that by letters mathworks means A-Za-z.
So spaces or symbols are not allowed.
Java won't help you there. It's intrinsic to matlab.
  댓글 수: 2
Guillaume 2014년 11월 14일
Matlab's high level functions are not particularly good for writing headers to files. You could use xlswrite assuming you have excel installed. Otherwise, you have to use low level functions:
fid = fopen('somefile.txt', 'wt');
fprintf(fid, 'Vol. (ml)\tConc. [wt%]\n');
for row = 1:size(m, 1)
fprintf(fid, '%f\t%f\n', m(row, 1), m(row, 2));

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by