comparison and replacement of values between 2 matrixes.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Antworten (1)
KALYAN ACHARJYA
am 25 Feb. 2020
Bearbeitet: KALYAN ACHARJYA
am 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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!