How to write a for loop to add to a label
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have labels from a tabel that I have extracted from the table but I am trying to add a _x, _y, and _z to each indivdual label. For example if the labels were 'arm' and 'leg' the end result would be 'arm_x, arm_y, and arm_z' . I want to do this using a for loop but I have no idea how to do this
0 commentaires
Réponses (1)
Kevin Holly
le 6 Nov 2022
Modifié(e) : Kevin Holly
le 6 Nov 2022
t = array2table(rand(3,3));
t.Properties.VariableNames = {'arm','leg','foot'}
for ii = 1:length(t.Properties.VariableNames)
t.Properties.VariableNames{ii} = [t.Properties.VariableNames{ii} '_x'];
end
t
Assuming you have the data in a matrix:
header = ["arm","arm","arm","leg","leg","leg","foot","foot","foot"];
data = rand(3,9);
m=[header;data]
t2 = array2table(data);
for ii = 1:3:length(header)
header(ii) = convertCharsToStrings([char(header(ii)) '_x']);
end
for ii = 2:3:length(header)
header(ii) = convertCharsToStrings([char(header(ii)) '_y']);
end
for ii = 3:3:length(header)
header(ii) = convertCharsToStrings([char(header(ii)) '_z']);
end
t2.Properties.VariableNames = header
0 commentaires
Voir également
Catégories
En savoir plus sur MATLAB Coder dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!