MATLAB: How to replace a row in one matrix with a particular row from a different matrix

replacing rows

I have one large matrix (64800×40) with an index number, latitude, longitude, and other data for the remaining columns.
Ex.
[ Index Lat Lon Data1 Data 2;
25102 -45.5 51.5 3 4;
25103 -45.5 52.0 4 7;
25104 -45.5 52.5 10 4;
25105 -45.5 53.0 12 2]
I've got another matrix with the same sort of data that I would like to use to replace particular rows in the first matrix. However, the second matrix is not the same size as the first (39×40).
Is there a script to run that would replace the data in the first matrix with the data from the second matrix? Perhaps using the index number?

Best Answer

Something like this maybe does what you want:
A = your large matrix
B = your smaller matrix
[y,x] = ismember(B(:,1),A(:,1)); % find where the indexes match in the 1st column
x = x(y); % save only the row numbers where the indexes match
A(x,:) = B(y,:); % replace the rows where the indexes match