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
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Prathusha Reddy
am 30 Jun. 2016
Kommentiert: Prathusha Reddy
am 1 Jul. 2016
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 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 30 Jun. 2016
a = 1:45;
reshape([a(:);nan(mod(-numel(a),4),1)],4,[])';
4 Kommentare
Walter Roberson
am 1 Jul. 2016
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.
Weitere Antworten (1)
Walter Roberson
am 30 Jun. 2016
If you have the signal processing toolbox, use buffer()
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!