How to create an array with first 100 elements as 1, next 100 as 2 and so on?
21 ビュー (過去 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!