## Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 1494
Number of posts: 2174

This Forum Only

Please help me creating a loop in matlab Posted by Blackbull78 on 24 Feb 2012 at 4:08 AM
Hi all,

Thank you in advance for the help you will provide, I really appreciate.
I am new to matlab so this could be very hard or very basic to do I don't know, Basically, I am trying to calculate a trajectory of an object on earth at different years.

I am calculating the distance that an object has done on earth using the Lat and long values.
My data are in three column, first column the year in which the distance was achieved (so the year is repeated as long as it is the same object), second column the latitude and third column the longitude.
What I want to do is calculate the distance in km between each point and sum them up for the same object. All the objects are consecutive in the columns but separated by a 0 (in the second and third column, so the program knows when to stop summing the points). My problem is that with what I wrote I only get the first object distance and I would like to get a loop so it goes to the next object below and so on.
Also, i would like to export the numbers in an excel file in three columns: year, distance and number of point that defined the distance. (I have 11000 object and more than 350,000 points that's why I need an automated program)
Can some one help me with this? Below is the program that I wrote nd example of my data:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
clear all
close all

load data.txt

earth_radius = 6371;

flag=1;
p=0;
angle=0;
for
while (flag==1);

p=p+1;
% Add angles between points.
angle=angle+distance(data(p,1),data(p,2),data(p+1,1),data(p+1,2));

% if the following point is [0 0], stop counting
if (data(p+2,1)==0 && data(p+2,2)==0)
flag=0;
end
end

%conversion from degrees to rad
ang_rad=pi*angle/180;

% conversion from rad to distance on the sphere in km.
distance=ang_rad*earth_radius;

disp('distance is (km) ');
disp(distance);

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Example of my data:

1922 39.87 60.61
1922 40.87 60.21
1922 41.87 59.86
1922 42.87 59.54
0 0
1924 29.87 64.9
1924 30.87 64.5
1924 31.87 64.11
1924 32.87 63.68
1924 33.87 63.23
0 0
1925 29.87 64.9
1925 30.87 64.5
1925 31.87 64.11
1925 32.87 63.68
0 0
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Thank you

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.