How to create an array with first 100 elements as 1, next 100 as 2 and so on?
6 次查看(过去 30 天)
显示 更早的评论
I want to create an array which looks like this:
[1 1 1 1 ...(100 time), 2 2 2 2...(100 times), 3 3 3 3....]
like this.
I'm very new to matlab, Any help?
2 个评论
Stephen23
2022-2-26
The simple MATLAB approach: https://www.mathworks.com/help/matlab/ref/repelem.html
采纳的回答
更多回答(1 个)
Vineet Kuruvilla
2022-2-26
n = 5;
A=[];
for i = 1 : 5
A=vertcat(A,i*ones(1,100));
end
disp(A)
1 个评论
Vineet Kuruvilla
2022-2-26
编辑:Vineet Kuruvilla
2022-2-26
You can change vertcat to horzcat if you want all in one row.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!