MATLAB: How to assign to the RowNames the sorted values of a table

assignMATLABrownamestblbvariables

a=10.089;
b=1.3061;
c=0.2248;
d=10.3138;
e=9.4294;
f=9.4015;
g=9.6263;
h=10.2859;
i=9.2834;
k=9.2834;
l=9.5584;
m=9.2046;
n=0.8844;
o=0;
p=0.8844;
q=0.2248;
r=0;
Fitness=[a b c d e f g h i k l m n o p q r]';
FiTernas = {'FitA1';'FitA2';'FitA3';'FitA4';'FitA5';...
'FitA6';'FitA7';'FitA8';'FitA9';'FitA10';...
'FitA11';'FitA12';'FitA13';'FitA14';'FitA15';...
'FitA16';'FitA17'}';
tblA = table(Fitness,'RowNames',FiTernas)
tblB = sortrows(tblA,{'Fitness'},{'descend'})
Solution:
tblA =
17×1 table
Fitness
_______
FitA1 10.089
FitA2 1.3061
FitA3 0.2248
FitA4 10.314
FitA5 9.4294
FitA6 9.4015
FitA7 9.6263
FitA8 10.286
FitA9 9.2834
FitA10 9.2834
FitA11 9.5584
FitA12 9.2046
FitA13 0.8844
FitA14 0
FitA15 0.8844
FitA16 0.2248
FitA17 0
tblB =
17×1 table
Fitness
_______
FitA4 10.314
FitA8 10.286
FitA1 10.089
FitA7 9.6263
FitA11 9.5584
FitA5 9.4294
FitA6 9.4015
FitA9 9.2834
FitA10 9.2834
FitA12 9.2046
FitA2 1.3061
FitA13 0.8844
FitA15 0.8844
FitA3 0.2248
FitA16 0.2248
FitA14 0
FitA17 0
Now my problem….
I need to be able to work with each Fitness number and his procedence… for example, the higher Fitness number: 10.314, I need to assign him from wich group comes, in this case comes from 'FitA4'… so will need something like: FitA4=10.314. Like that with the rest numbers and RowNames…
I appriciate any help.

Best Answer

"...''FitA4'... will [become]: FitA4=10.314."
This is called dynamic variable naming and it's not a good strategy. You already have a very nice, tidy table so don't break it apart into separate variables. Use the table itself. The one line below shows how to get the Fitness value of FitA4 from the table.
x = tblB.Fitness(ismember(tblB.Properties.RowNames, 'FitA4'))
Here's how to get several values
x = tblB.Fitness(ismember(tblB.Properties.RowNames, {'FitA4','FitA2','FitA11'}))