Problem 44322. Make one vector from two others
You are given two vectors of equal length. Your task is to create a MATLAB script that will repeat all of the values in the first matrix a number of times equal to the corresponding place in the second matrix. For example:
M1=[1 3 5 7] and M2=[2 4 0 6]
You will want to have your output vector be two ones, four threes, zero fives and six sevens, or [1 1 3 3 3 3 7 7 7 7 7 7] You can assume that all of the values in M2 are greater than or equal to zero.
While this can be done with a for loop and repmat, I'm hoping that the brilliant minds here in Cody can come up with a better way to do this!
Solution Stats
Solution Comments
Show commentsProblem Recent Solvers52
Suggested Problems
-
Replace NaNs with the number that appears to its left in the row.
3049 Solvers
-
6701 Solvers
-
Back to basics 12 - Input Arguments
616 Solvers
-
Sum the 'edge' values of a matrix
391 Solvers
-
Find out value of sine given by degree.
351 Solvers
More from this Author80
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!