comparison and replacement of values between 2 matrixes.

1 view (last 30 days)
I have 2 Matrixes of n*4 size, where the first 3 columns are co-ordinate values and the 4th being a value for the co-ordinate.
the matrixes dont occupy the same space (co-ordinate wise) and i am wanting to find and replace the values in the 4th column of the first matrix, with the values in the 4th column of the 2nd matrix that have corresponding co-ordinate values (columns 1-3).
I am currently doing this through a series of for and if loops checking the co-ordiantes of each row of the 2nd matrix against the 1st and replacing the value of the first when they match, but given the size of the matrixes (n~1000000), this takes a long time.
Is there any way i could code this process differently to speed it up?

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 25 Feb 2020
Edited: KALYAN ACHARJYA on 25 Feb 2020
"i am wanting to find and replace the values in the 4th column of the first matrix, with the values in the 4th column of the 2nd matrix that have corresponding co-ordinate values (columns 1-3)"
n=5; % Any Value, row number
%Before Exchange 4th cloumn
% Any Radom mat
mat1=randi(20,[n,4])
mat2=randi(20,[n,4])
temp_data=mat1(:,4);
mat1(:,4)=mat2(:,4);
mat2(:,4)=temp_data;
%After Exchange 4th cloumn
mat1
mat2

Categories

Find more on Characters and Strings in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!