MATLAB Answers

How can i convert 160by1 column vector into 16by145 such that first column contain 1 to 16 and second column 2 to 17 and so on?

1 view (last 30 days)
rajesh kumar
rajesh kumar on 30 May 2020
Answered: Walter Roberson on 30 May 2020
i have 160x1 column vector. i have to convert that into matrix form such that first column contain 1 to 16 and second coulumn contain 2 to 17 and so on

Answers (2)

Carlos Alejandro Peñuelas Angulo
Edited: Carlos Alejandro Peñuelas Angulo on 30 May 2020
With a for loop you can iterate over the index you want to start each row of the new matrix. Something like this:
% Original vector
vec = (1:160)';
% Matrix creation
mat = zeros(145, 16);
rowSize = 16;
for i = 1:145
mat(i,:) = i:i+rowSize-1;
end
% Transpose the new matrix
mat = mat';
The '-1' is to avoid the overflow of the indexes.
Hope this help you.

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!