adding element to the beginning of an array

12 ビュー (過去 30 日間)
Ali Abdulkarim
Ali Abdulkarim 2020 年 7 月 21 日
コメント済み: Ali Abdulkarim 2020 年 7 月 22 日
I have a array which has been initialized with zeros, I would like to add four elements each time at the beginning of it while keeping its size the same,
I want to add the first four elements from a array to the first four elements to a second array(initialized with zeros) and then the next four till we have all the elements from the first one transfer to the second with the order that I have mentioned perviously and with the same manner.
I think it can be done without using loops, I would like to see the best way that Matlab offers to do this.
for example I have:
a = randi(10,1000,1);
% I want to add the first for elements from a to the beginning of b while keeping the size of b the same, and then the next four from a
% to be and so on..
b = zeros(2048,1);
Any help would be really appreciated :)

採用された回答

madhan ravi
madhan ravi 2020 年 7 月 21 日
b(1:numel(a)) = a
  7 件のコメント
madhan ravi
madhan ravi 2020 年 7 月 22 日
I answered your original question.
Ali Abdulkarim
Ali Abdulkarim 2020 年 7 月 22 日
In my original question, I have mentioned this, In other words I am not trying to extend the question, I have already accepted your answer, becuase It was helpful, thanks anyways

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by