Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Reorder elements of 1D matrix across separate rows in a new matrix

1 Ansicht (letzte 30 Tage)
GioPapas81
GioPapas81 am 25 Apr. 2019
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Hi guys,
I have a long matrix and I want to reorder elements using a specified point step, across separate rows of a new matrix.
For example, I have the attached Matrix=(1:7200) in size. In step 1, I want to take elements Matrix(1:10) and add them in the first row of a new New_Matrix. Then, in step 2, I want to take elements Matrix(1:20) and add them in the second row of the New_Matrix. In step 3, I want to take elements Matrix(1:30) and add them in the third row of the New_Matrix, and so on (using let's say always this 10 point step).
I have tried quite few different ways but it starts being convoluted as a process, so I thought to ask you as I am sure there is a more concise and efficient way to perform this.
Thank you,
George
  2 Kommentare
Akira Agata
Akira Agata am 26 Apr. 2019
How about the following way?
load('Matrix.mat');
sz = size(Matrix);
New_Matrix = repmat(Matrix,sz(2)/10,1);
for kk = 1:sz(2)/10
New_Matrix(kk,kk*10+1:end) = NaN;
end
GioPapas81
GioPapas81 am 26 Apr. 2019
Many thanks Akira, that works. I only modified your lines a bit, to directly include the desired elements per row, without the NaN values.
for kk = 1:sz(2)/10
New_Matrix{kk,1}=Matrix(kk,1:kk*10);
end

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by