titel for tables with spce between the words

I would like to have spece between subject and number, but the error is, that is not allowed to have space in variables. Is there a possibility? I wouldn't like to have underscores.
table_subjects = cell2table(table(1:end,:),'VariableNames',{'Subject number' 'Gender' 'Age' 'Weight' 'Height' 'Systolic_pressure' 'Diastolic_pressure'}),
Error in Liste_aller_Matlabfiles (line 50)
table_subjects = cell2table(table(1:end,:),'VariableNames',{'Subject number' 'Gender' 'Age' 'Weight' 'Height' 'Systolic_pressure'
'Diastolic_pressure'})

 Accepted Answer

The R2019b release allows spaces and other (inluuding Unicode) characters in table variable names. Upgrade to it and you will be able to do what you want.

9 Comments

I wasn't aware of that, Star...as apparent from the (now deleted) Answer I posted. Do those have to be quoted? I've not yet gotten R2019 downloaded/installed so can't check directly...
I’ve only recently started using them. They may not be in the original R2019b, and may be installed in an update (3 so far). I don’t remember precisely.
To use them in a user-created table, they work just as any other 'VariableNames' cell array.
To import them from a file using readtable, it’s necessary to use the 'PreserveVariableNames',1 name-value pair.
"To use them in a user-created table, they work just as any other 'VariableNames' cell array. "
So you could type something like
t.Var Name With Space=pi;
if there's a variable of the name {'Var Name With Space'}? That seems a parsing nightmare if so.
Or, you're saying can only use then in the cellstr array syntax modes (more likely, I'd guess)?
The character for ‘pi’ is a Unicode character, and I am not certain how to use those. However, this definitely works:
VN1 = compose('Name With Space=%.3f',pi);
T = array2table(randi(40,3,2), 'VariableNAmes',{VN1{:},'T (°C)'})
producing:
T =
3×2 table
Name With Space=3.142 T (°C)
_____________________ ______
17 13
19 32
31 19
Here are the Release Notes for this feature. One quote from those notes: "You can access any table or timetable variable using dot notation. However, if a variable name is not a valid MATLAB identifier, then you must specify the name as an expression within parentheses following the dot. The expression can be a variable name enclosed in quotation marks, or a function that returns a character vector or string scalar."
So if your table T has variable names Age and Work Address:
T = table(42, "3 Apple Hill Drive", 'VariableNames', ...
["Age", "Work Address"])
The following will work to retrieve Age:
T.Age
T.('Age') % Or T.("Age")
T{1, 'Age'} % Or using "Age"
To retrieve Work Address:
T.('Work Address') % Or the string equivalent
T{1, 'Work Address'}
But the following wouldn't. It would probably throw an error, or it could concatenate together the variable Work from T and the result of evaluating the command Address (if wrapped in square brackets or curly braces.)
T.Work Address
@Steven — Thank you. I’ve not needed to get that much into using the new variable name options, so I appreciate your clarification.
"The character for ‘pi’ is a Unicode character, and I am not certain how to use those."
Star-- I was simply writing pi above as an example of an assignment reference to an existing table name with embedded blanks....
Steven, any guesstimates as to the added parsing overhead this refinement requires? While nice for presentation, I wonder about performance.

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!