Overwriting a part of an array
Mostrar comentarios más antiguos
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?
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Cell Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!