MATLAB Answers

New point calculation - for loop

2 views (last 30 days)
em_++ on 14 Jun 2021
Commented: em_++ on 14 Jun 2021
Hi there!
Ive got a question regarding new point calculation... So i got 2 Points (Latitude,Longitude) and I want to calculate 7198 new points between those two... So because there are so many i wanted to use a for loop.
  1. so first step is to calculate the direction angle (this one i did get correct)
  2. then calculate the distance between the points with pythagoras : 2700
  3. new array s = zeros(7200,1) where i want to put the previously (2.) calculated distances ++
  4. for loop:
for j = 1:7200
s(j,1) = distance ++; <- Here is the problem

Answers (1)

Scott MacKenzie
Scott MacKenzie on 14 Jun 2021
Edited: Scott MacKenzie on 14 Jun 2021
No need for a loop:
% arbitrary point for beginning (perhaps longitude)
x1 = randi([1 1000],1);
y1 = randi([1 1000],1);
% arbitrary point for ending (perhaps latitude)
x2 = randi([1 1000],1);
y2 = randi([1 1000],1);
n = 7200; % number of points from beginning to ending
pf = polyfit([x1 x2], [y1 y2], 1);
x = linspace(x1, x2, n);
y = polyval(pf,x);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!