필터 지우기
필터 지우기

randomly sample a pair of values in a double

조회 수: 1 (최근 30일)
ELISABETTA BILLOTTA
ELISABETTA BILLOTTA 2022년 12월 8일
댓글: Jan 2022년 12월 8일
I have two doubles of the type coord_iso=65x2 double and coord_ce=65x2 double (they are all pairs of geographic coordinates).
I need to RANDOM sample one of the coordinate pairs inside the coord_iso. how can I do?
then with this randomly sampled pair and the first pair of coord_ce (row 1) I have to calculate the distance in km. in this case I was thinking of using distance and then the value/180*pi*6371.
you can help me?

채택된 답변

Star Strider
Star Strider 2022년 12월 8일
I need to RANDOM sample one of the coordinate pairs inside the coord_iso. how can I do?
One option —
RandomRow = randi(size(coord_iso,1));
RandomResult = coord_iso(RandomRow,:)
These can be combined into one assignment —
RandomResult = coord_iso(randi(size(coord_iso,1)),:)
Example —
coord_iso = [ 91.36 14.46
91.38 14.50
91.42 14.51
91.46 14.51
91.49 14.47];
RandomResult = coord_iso(randi(size(coord_iso,1)),:)
RandomResult = 1×2
91.3800 14.5000
.

추가 답변 (1개)

Jan
Jan 2022년 12월 8일
You want a random integer in the range [1, 65] as index? randi([1, 65])
I have no idea, what "distance and then the value/180*pi*6371" means.
  댓글 수: 2
ELISABETTA BILLOTTA
ELISABETTA BILLOTTA 2022년 12월 8일
for example, coord_iso (5x2 double)= 91,36 14,46
91,38 14,50
91,42 14,51
91,46 14,51
91,49 14,47
writing
a=coord_iso(randi(5,1))
I can randomly select a value in the first column. how do I then select the value of the second column corresponding to the one selected randomly in the first column?
for example in this case if a=91.38, how do I then select the 14.50 which is its equivalent but in the second column?
Jan
Jan 2022년 12월 8일
To select the complete row:
a = coord_iso(randi(5,1), :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Geographic Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by