Assigning specific values to a vector of length N without for loop?

Suppose i have T = [40 50 60 70], if i want to create a vector of length N that is subdivided by length(T) so that the first N/length(T) entries are 40, the next N/length(T) entries are 50, etc., is there an efficient way to do this without using loops? I was looking at repmat but i don't think that can do it. Any suggestions would great. Thanks

 Accepted Answer

T = [40 50 60 70];
N = 12;
Tv = reshape(repmat(T,N/length(T),1),N,1)'

1 Comment

Thanks Sean...was just looking at reshape but was still having trouble figuring out how to get it to work with repmat to get it to do what i needed. Thank you

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!