# How to generate matrix using MATLAB ?

28 views (last 30 days)
Explorer on 14 Feb 2014
Commented: Explorer on 15 Feb 2014
How to generate matrix of 24 * 96 order using MATLAB as shown in figure. Jos (10584) on 15 Feb 2014
take care … your MS product activation failed … ;-)

Shashank Prasanna on 14 Feb 2014
There isn't a right answer. Here is one:
X = eye(4);
X(:,repmat(1:4,4,1))
Change 4 to something else if you want to wider or taller.

Wayne King on 14 Feb 2014
Edited: Wayne King on 14 Feb 2014
I'm sure there are many different ways:
X = zeros(1,96);
X(1:4) = 1;
K = 0;
for nn = 1:24
Y(nn,:) = circshift(X,K,2);
K = K+4;
end
Assuming that each row of 96 elements has 4 1's and each row is a shifted version of the previous one.
Explorer on 15 Feb 2014
Thanks

Roger Stafford on 14 Feb 2014
Here's another way:
m = 4; n = 24;
x = reshape(diff(floor((m*n+m*(0:m*n^2))/(m*n+1))),n,m*n);
Explorer on 15 Feb 2014
Thanks

Jos (10584) on 15 Feb 2014
An easy way:
m = kron(eye(24),ones(1,4))
Explorer on 15 Feb 2014