How to write a for loop to add to a label
14 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Kevin Holly
2022 年 11 月 6 日
編集済み: Kevin Holly
2022 年 11 月 6 日
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!