I am trying to create a small script that will allow me to expand the perimeter based off coordinates. The program is running through the variables correctly when I look at the workspace, but I can't get it to write the results to the structure multiple times. It will only write to the structure once. Am I missing a nested loop?
load 'lat_lon.mat'
new_coord = [];
for i = 1:length(lat_lon)
1
new_coord.Lat = [lat_lon(:,[1])];
new_coord.Lon = [lat_lon(i:,[2])];
2
%Finds the radius of the Earth at given latitude
radius = 6372 * cos(lat_lon(i,[1])/180 * pi)
3
%Converts given perimeter expansion to degrees
lat_nat_deg = nm2deg(3.5, radius);
new_coord.lat_exp = [lat_nat_deg];
nat_deg = nm2deg(3.5);
new_coord.lon_exp = [nat_deg];
4
new_coord.latitude = [lat_lon(i,[1]) + lat_nat_deg];
5
new_coord.longitude = [lat_lon(i,[2]) + nat_deg]
end
The lat_lon.mat is :
Lat_Long = [60.8427194, -042.7969500; ...
60.8646972, -042.5323889; ...
60.7640417, -042.5178639; ...
60.5882139, -042.8185056; ...
60.8080111, -042.8507500; ...
60.8069889, -042.8374167; ...
60.8083028, -042.8278361; ...
60.8114056, -042.8186167; ...
60.8152306, -042.8117389; ...
60.8203694, -042.8055667; ...
60.8256528, -042.8013611; ...
60.8315167, -042.7985083; ...
60.8374056, -042.797078; ...
60.8427194, -042.7969500];

 채택된 답변

Chad Greene
Chad Greene 2016년 3월 17일

0 개 추천

The loop you've written overwrites the results each time through the loop. Any information you want to log such as newcoord.latitude must be indexed to i. (Better yet, change i to k because i is the imaginary unit in Matlab and defining i as a variable can occasionally cause errors.)
Here are two ways you can organize your structure:
for k = 1:10
newcoord.lat{k} = randi(90,1,2);
anotherway(k).lat = randi(90,1,2);
end

댓글 수: 1

Bob Murphy
Bob Murphy 2016년 3월 22일
That's exactly what I was trying to do! If I wanted to save the results as a double like the provided coordinates were, is there a simple edit to do that?

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2016년 3월 17일

댓글:

2016년 3월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by