Creating a 2-D matrix from a 1-D Array?
Show older comments
Considering that I have an array of A = [150 11 12 134 130 152]. How to replicate these elements in this array to get a matrix of size 256*256.
Accepted Answer
More Answers (2)
David Sanchez
on 5 Jul 2013
You do not make clear how you want to replicate your data, but this is a way:
A = [150 11 12 134 130 152];
L = numel(A); % number of elelments in A
M = zeros(256); % initialize the matrix
% assigin values to first row
for k = 0:floor(256/L)
M( 1 , (k*L+1):((k+1)*L) ) = A;
end
% make sure you only have your 256 columns
M = M(:,1:256);
% copy first row to the rest of rows
for k=2:256
M(k,:) = M(1,:);
end
1 Comment
Sabarinathan Vadivelu
on 5 Jul 2013
Andrei Bobrov
on 5 Jul 2013
Edited: Andrei Bobrov
on 5 Jul 2013
out = A(randi(numel(A),256,256));
or
m = 256;
n = 256;
A1 = repmat(A,1,ceil((m+n-1)/numel(A)));
out = hankel(A1(1:m),A1(m:m+n));
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!