matrix add in matlab
3 views (last 30 days)
Show older comments
how do i write i code for [ 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 ]
please help
0 Comments
Answers (1)
John D'Errico
on 14 Sep 2015
Edited: John D'Errico
on 14 Sep 2015
Simple.
v = [ 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 ];
I suppose, if your real question is if you knew the number of replicates for each element, you might use a code like replicator. I've attached it, although I am sure there must be a similar code on the file exchange.
v = replicator(1:6,[2 3 3 3 3 1])'
v =
1 1 2 2 2 3 3 3 4 4 4 5 5 5 6
2 Comments
Steven Lord
on 14 Sep 2015
There's a "similar code" in MATLAB as of release R2015a.
v = repelem(1:6, [2 3 3 3 3 1])
See Also
Categories
Find more on Get Started with MATLAB 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!