Overwriting a part of an array
이전 댓글 표시
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?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!