Overwriting a part of an array
Show older comments
I have arrays of fixed size, and starting at a fixed location, I want to overwrite the values in the array with values of another array of variable length.
For example:
A = [1 3 4 2 6 7 4 6 7]
B1 = [9 8 5]
B2 = [5 5 4 3]
I want to overwrite the values in A, starting at position 2, with the values of B. (B is always shorter than A) This would yield:
C1 = [1 9 8 5 6 7 4 6 7]
C2 = [1 5 5 4 3 7 4 6 7]
One way to achieve this is:
C1 = A;
C1(2:1+size(B1,2)) = B1;
I was wondering if there is a more direct/elegant way, that doesn't require the size(B1,2) parameter?
Accepted Answer
More Answers (0)
Categories
Find more on Cell Arrays 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!