Calculating Change in 1 dimensional array

Hello! I have a 1 dimensional array of latitude values (which has dimensions of 1 X 224). How would I calculate the change in latitude, aka delta latitude?
Thank you so much!

 Respuesta aceptada

Star Strider
Star Strider el 22 de Ag. de 2014

1 voto

If they are decimal values, use the diff function. Otherwise, you will have to convert them into decimal values (from degrees-minutes-seconds) first.

2 comentarios

Stephanie Goldstein
Stephanie Goldstein el 22 de Ag. de 2014
Alright, thank you!
Star Strider
Star Strider el 22 de Ag. de 2014
My pleasure!

Iniciar sesión para comentar.

Más respuestas (2)

Image Analyst
Image Analyst el 22 de Ag. de 2014

1 voto

Subtract the two latitudes you want to calculate the difference between? Or am I missing something?

2 comentarios

Stephanie Goldstein
Stephanie Goldstein el 22 de Ag. de 2014
I need to calculate the difference between all of the latitudes in the array. For instance, I need to subtract the second from the first latitude, the third from the second latitude, and so on. Does that make sense?
Image Analyst
Image Analyst el 22 de Ag. de 2014
That's what diff() does. Just make sure your angles are in decimal degrees or radians and not some kind of funky degrees/minutes/arcseconds form.

Iniciar sesión para comentar.

Stephanie Goldstein
Stephanie Goldstein el 22 de Ag. de 2014

0 votos

I need to calculate the difference between all of the latitudes in the array. For instance, I need to subtract the second from the first latitude, the third from the second latitude, and so on. Does that make sense?

4 comentarios

Star Strider
Star Strider el 22 de Ag. de 2014
Editada: Star Strider el 22 de Ag. de 2014
It does if it makes sense in the context of your problem. The diff function will do that for you. You have to convert your latitudes to decimal degrees first, though. If you don’t already have a function to do that, this anonymous function will do it:
dms2deg = @(d,m,s) d + m/60 + s/3600;
To convert 45°30' to decimal degrees:
dd = dms2deg(45,30,0);
Image Analyst
Image Analyst el 22 de Ag. de 2014
The diff() function does it for adjacent elements in an entire array, though it will also work on an array of length 2. If you have two arbitrary angles - maybe they're two different variables or two non-adjacent elements in some array - then you'd have to subtract them manually or one at a time.
Do you have the mapping toolbox? Maybe there is some function in there that takes angles in degrees and arseconds and converts to decimal degrees or radians.
Stephanie Goldstein
Stephanie Goldstein el 22 de Ag. de 2014
Great. Thanks. How would I apply that function (used to convert to degrees) to the entire array and not to just one cell?
Star Strider
Star Strider el 22 de Ag. de 2014
Editada: Star Strider el 22 de Ag. de 2014
According to the online documentation, the Mapping Toolbox has the dms2degrees function that does the same thing. I suggest you use it instead of the one I provided. (I don’t have the Mapping Toolbox, so just now thought to look.)

Iniciar sesión para comentar.

Preguntada:

el 22 de Ag. de 2014

Editada:

el 22 de Ag. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by