I have a array of 1X45 double .I have to rearrange and copy into another array. First four values to 1st row, next 4 values to 2nd row and so on

4 次查看(过去 30 天)
I have a array of 1X45 double .I have to rearrange and copy into another array. First four values to 1st row, next 4 values to 2nd row and so on
  3 个评论

请先登录,再进行评论。

采纳的回答

Andrei Bobrov
Andrei Bobrov 2016-6-30
a = 1:45;
reshape([a(:);nan(mod(-numel(a),4),1)],4,[])';
  4 个评论
Walter Roberson
Walter Roberson 2016-7-1
The mod() expression figures out how many values need to be added to bring the total number of values up to a multiple of 4, and the nan() part of it says to create a vector that many elements long each element of which is nan (Not A Number). The effect of the code is to pad out the array to be a multiple of 4 long, by adding as many nan on the end as needed to make a multiple of 4.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2016-6-30
If you have the signal processing toolbox, use buffer()

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by