How to obtain vector of specific values in MATLAB
Show older comments
Hello all, I want to obtain a 16 vectors each of dimension 96 by 1 such that in 1st vector, the index position 1 to 6 have values 1 and rest of the index position have values zeros.
In 2nd vector the index postion 7 to 12 have value 1 and rest of the index position have values zeros.
In 3rd vector index position 13 to 18 have value 1 rest of the index position have values zeros.
Continuing in this manner, in 16th vector the index position 91 to 96 have value 1 and at all other index positions the value is zero.
Any help in this regard will be highly appreciated.
Accepted Answer
More Answers (2)
M = kron(eye(16),ones(6,1))
or
M = repelem(eye(16),6,1)
It's not a good idea to dynamically define variables. Read - Why Variables Should Not Be Named Dynamically
You can make a 96x16 matrix, in which nth column corresponds to nth vector as required. In this way, your data is easy to access via indexing.
temp=ones(6,1);
out=temp;
for k=1:15
out=blkdiag(out,temp);
end
disp(out)
1 Comment
charu shree
on 17 Mar 2023
Categories
Find more on Logical 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!