how to duplicate data length of a workspace ?
1 次查看(过去 30 天)
显示 更早的评论
hello all,
i have a data in workspace, for example a column of 1 2 3 4 , and i have an other data with a column with a N length, i want to have a new column that contain the 1 2 3 4 and repeat it till it arrive to N length, how to do that ?
thank you.
0 个评论
采纳的回答
更多回答(1 个)
James Tursa
2016-7-21
编辑:James Tursa
2016-7-21
E.g., assuming N is divisible by 4:
result = repmat(column_vector,N/4,1);
If you have to cover cases where N is not divisible by 4, e.g.,
result = repmat(column_vector,ceil(N/4),1);
result = result(1:N);
or another way
result = column_vector(mod(0:N-1,4)+1);
If your column_vector is not really 4 elements but something else, simply replace 4 with numel(column_vector) in the above code.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!