Add Column Data to Existing Data Array at Specific Locations MATLAB
Show older comments
Hi - I have a matrix of data that is A = [ 1 1 1 1; 2 2 2 2; 3 3 3 3; 4 4 4 4; 5 5 5 5] and B = [ 6 6; 7 7; 8 8; 9 9; 10 10] and an index ind = [ 1 0 0 0 1 0 ] that changes where the insertion point or "1" is located in the column order in other arrays. I need to insert the data of B into A but in the place of index == 1. So, the final matrix needs to look like C = [ 6 1 1 1 6 1; 7 2 2 2 7 2; 8 3 3 3 8 3; 9 4 4 4 9 4; 10 5 5 5 10 5] or like this below. I've searched the web but haven't seen the unique answer and I cannot seem to develop a trick to accomplish this...Thank you!
A looks like this
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
B looks like this
6 6
7 7
8 8
9 9
10 10
C final looks like this (based on the index "ind"
6 1 1 1 6 1
7 2 2 2 7 2
8 3 3 3 8 3
9 4 4 4 9 4
10 5 5 5 10 5
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!