Sure you can. You can use the find function to find the index at which the 2nd and 3rd column match, and then copy the elements over.
Your code could look like this:
origMat = [10521 -45.5 50.5;
10522 -45.5 51.5;
10523 -45.5 52.5];
newMat = [0 -45.5 52.5;
0 -45.5 52.5;
0 -45.5 51.5;
0 -45.5 50.5];
for ii = 1:size(newMat,1)
idxLocation = origMat(:,2)==newMat(ii,2) & ...
origMat(:,3)==newMat(ii,3);
if ~isempty(idxLocation)
newMat(ii,1) = origMat(idxLocation,1);
end
end
format short g
newMat
This gives me
newMat =
10523 -45.5 52.5
10523 -45.5 52.5
10522 -45.5 51.5
10521 -45.5 50.5
Best Answer