How to replace a row in one matrix with a particular row from a different matrix
3 ビュー (過去 30 日間)
古いコメントを表示
I have one large matrix (64800x40) 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 (39x40).
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?
1 件のコメント
Rik
2017 年 7 月 14 日
You seem to be on the right track. You are nearly at a working solution (although you are closest to a very inefficient method). What have you tried?
採用された回答
James Tursa
2017 年 7 月 14 日
編集済み: James Tursa
2017 年 7 月 14 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!