assign name row to table
8 views (last 30 days)
Show older comments

Sistemi_check=table(string(K_Nome),K_idxInstrument');
LastName = {"Sanchez";"Johnson"};
Sistemi_check.Properties.RowNames=LastName;
>> check_Instrument
Error using .
The RowNames property must be a string array or a cell array, with each name containing one or more
characters.
Error in check_Instrument (line 22)
Sistemi_check.Properties.RowNames=LastName;
2 Comments
Answers (2)
Walter Roberson
on 31 May 2023
Either use
LastName = ["Sanchez";"Johnson"];
Sistemi_check.Properties.RowNames=LastName;
or else
LastName = {'Sanchez';'Johnson'};
Sistemi_check.Properties.RowNames=LastName;
That is you can use a cell array of character vectors, or you can use a string() array, but you cannot use a cell array of string() objects.
3 Comments
Walter Roberson
on 1 Jun 2023
Sistemi_check = table("first", 123)
LastName = ["Sanchez";"Johnson"];
Sistemi_check.Properties.VariableNames=LastName
Sistemi_check = table("first", 123)
LastName = {'Sanchez';'Johnson'};
Sistemi_check.Properties.VariableNames=LastName
Sulaymon Eshkabilov
on 31 May 2023
Here is a plain example how to rename row and column names in a table array:
t1 = date;
t2 = '01-June-2023';
t3 = '10-June-2023';
t4 = '20-June-2023';
T = {t1; t2; t3;t4};
D = table(T);
D.N = [10:10:40]'
% Add row names:
LastName = {'Sanchez';'Johnson'; 'Brown'; 'Green'};
D.Properties.RowNames=LastName
% Change column names:
Col_Name = {'Date', 'Number'};
D=renamevars(D,{'T', 'N'}, Col_Name)
0 Comments
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!