Suppose i have
23points of xy coordinate , where 1st column is X coordinate , 2nd column is Y coordinate , it is a 23x2 matrix,
I have another seperate data to tell me which 5 points to take.
is there anyway i can do a neat work instead of for loop ? Because i need to calculate the distance using for loop later on and with hundreds of points which is lagging my system.
i wish to print out the 5 points , and have result of the x y coordinate into 1 matrix. lets says i wish to get point 2 , 3 , 5 , 8 , 9 base on 1st column of table 2
table 1
10.6100 16.9500
27.0800 18.6300
41.2900 18.2600
60.5000 20.1700
1.7800 11.5200
16.8500 11.1000
29.9500 11.8500
46.6400 11.4900
60.5000 11.8000
8.3500 5.1600
40.3900 6.8300
55.0000 7.1200
2.9800 19.3000
15.3600 16.1600
12.9900 20.2000
44.5700 21.2000
25.4900 4.6500
41.5800 14.9900
50.9100 14.3700
50.5000 20.0200
60.5000 14.6500
2.6800 4.8800
63.0200 3.8600
table 2
2 4 4 4
3 20 9 21
5 21 21 20
8 19 19 19
9 16 20 16
Expecting Results from table from 1 with reference to first row of table 2 :
27.0800 18.6300
41.2900 18.2600
1.7800 11.5200
46.6400 11.4900
60.5000 11.8000

 Accepted Answer

LEt A, B be your two matrices.
iwant = A(B(:,1),:);

4 Comments

thanks bro for your kind help i have 1 last problem which i request , if things can be done faster.
anchorLoc = 23 points in the table 1,
mobileLocEst is random generated 600 points in matlab
for each point in mobileLocEst , i wanna calculate the distance with reference to 5 points (anchorLoc)
for i = 1:600
distanceEst = sqrt(sum( (anchorLoc) - repmat(mobileLocEst(m,:),N,1)).^2 , 2));
end
so to speed up processing , is there any fast way out ?
cause i need to process it 600 times and later on i have some calculation in my coding.
sorry to mention , each mobileLocEst will be calculating with reference of 5 points (anchorLoc) so its there a simplify method ? so the 5 selected (anchorLoc) at different mobile will change everytime.
Read about pdist2. This will give your distances on providing two set of points.
yes i understand pdist2 calculate euclidean distance between 2 points.
thank you for your help.

Sign in to comment.

More Answers (0)

Asked:

on 4 Nov 2020

Commented:

on 4 Nov 2020

Community Treasure Hunt

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

Start Hunting!