Add columns to tables with loops

11 次查看(过去 30 天)
I want to create a first column for my table, after a loop. I tried like this:
%N(mxn)
i=1;
while i<= size(N,1)
capa(i) = fprintf('Bar #',int2str(i));
i=i+1;
end
Furthermore I used sprintf.
The result in this case of three rows, it would be:
Bar 1
Bar 2
Bar 3

采纳的回答

Ameer Hamza
Ameer Hamza 2020-5-19
See this example
t = array2table(rand(3)); % example table
rows = compose('Bar %d', [1 2 3]);
rows = vertcat(rows{:});
T = [table(rows, 'VariableNames', {'labels'}) t];

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by