How to put rows of a matrix in another matrix column?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
parham fekrkon
am 16 Mai 2020
Beantwortet: William Alberg
am 16 Mai 2020
- Hi everyone.
I have a 243938x1 Data matrix, and what I want to do is that I want to take the first 100 data (rows) of this matrix and put it in the first column of a defined Matrix Y.
then take the second 100 data (101-200) and put it in the second column of Y, and so on, till the Y Matrix is a 100x200 matrix.
can anyone help me with that? thanks .
0 Kommentare
Akzeptierte Antwort
William Alberg
am 16 Mai 2020
data = rand(243938,1); % generate test data
n = 2; % Columns in Y
Y = nan(100,n); % initiate Y
% method 1, using forloop
for i = 1:n
Y(1:100,i) = data( (1 + 100*(i-1)):(100*i));
end
% method 2, using reshape command
Y1 = reshape(data(1:(n*100)),[100,n]);
Here is 2 methods that scales if you want Y to have more than 2 columns
Alternatively, you can just use: Y = [data(1:100), data(101:200)]
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dimensionality Reduction and Feature Extraction 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!