Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help Guys,,, For Statemente in MATLAB

Status
Not open for further replies.

Rihanna

Junior Member level 1
Junior Member level 1
Joined
Jul 24, 2012
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,396
Hello Guys

Can you please tell me whether this code is correct or not??

this code use to calculate all distances from A to J points on the map ( has longitude and latitude ), the starting point coordinates ( Lat and Long ) is 3.682043 and 101.523710 and the destination is 2.227804 103.35091

for p1=3.682043:-0.5:2.227804
for p2=101.523710:0.5:103.735091


a5= 2.227804;
b5=103.35091;

[dDgree] = distance(p1,p2,a5,b5); %% this function used to find a distance between two coordinates

end
end


2untitled.JPG


I'll appreciate it
 
Last edited:

From the way the loops are nested, it appears you will receive about 100 data. Is this what you wish?

This comes from not being familiar specifically with Matlab syntax.

Also the rightmost 'lon' values are different.
103.735091 and 103.35091.
 

If you want to calculate the lengths of just the line segments labelled A to J, then you need to do it in 2 stages - first A to F as you keep lat constant and the G to J as you keep lon constant. Also, I don't think you need the assignments for a5 and b5 inside the loop. So I would do it like this:

% -----------

a5= 2.227804;
b5=103.35091;

i=1;
p1 = 3.682043;
for p2=101.523710:0.5:103.735091
AtoF(i) = distance(p1,p2,a5,b5); %% this function used to find a distance between two coordinates
i = i+1;
end

i=1;
p2 = 101.52371;
for p1=3.682043:-0.5:2.227804
GtoJ(i) = distance(p1,p2,a5,b5); %% this function used to find a distance between two coordinates
i = i+1;
end

% -------------

I've put the results into two separate arrays AtoF and GtoJ and used the counter i for indexing them. You may have to pay special attention to the end points (it's not clear from your diagram whether they should be included) - and you may need to fine-tune the step size (0.5) for each loop to get the correct number of results which includes one near the end point.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top