Loop or no Loop?

조회 수: 11 (최근 30일)
Pantelis Saviolakis
Pantelis Saviolakis 2014년 2월 24일
댓글: Pantelis Saviolakis 2014년 2월 24일
Hello,greetings from Greece.I have a large data set with columns(longitude,latitude,u,v,w,etc).Because longitude and latitude are discontinuous in some points,i have to separate the data set in 81 parts (not equal in length) to take a different figure of each part(where longitude and latitude are continuous). I have done this manually but i was wandering if there was a way to do this in a loop(to be more beautiful),because the code i use every time is the same. The only thing that change is as an example: for the first figure i=1:1:517 , for the second figure i=518:1:721 ,for the third i=722:1:1200 ... where i is the line of the dataset and its size is not presized(the other code is the same).If someone can help, i would be gratefull.

채택된 답변

Iain
Iain 2014년 2월 24일
You need to figure out the right process for splitting your dataset.
Something like:
dlat = abs(diff(latitude));
datasets_end_at = find(dlat > 1);
datasets_start_at(1) = 1;
datasets_start_at(2:(numel(datasets_end_at)+1)) = datasets_end_at + 1;
datasets_end_at(end+1) = numel(latitude);
for i = 1:numel(datasets_start_at)
section_indices = datasets_start_at(i):datasets_end_at(i);
....

추가 답변 (1개)

Pantelis Saviolakis
Pantelis Saviolakis 2014년 2월 24일
Thank you for your direct answer to my question. I have tried it but i take only 2 figures instead of 81.I will see if i do sth wrong.Thanks again.
  댓글 수: 2
Iain
Iain 2014년 2월 24일
You will need to adapt what I gave you for what you need:
find(dlat > 1); might need to be:
find(dlat > 0.0001);
dlat = abs(diff(latitude)); might need to be:
d_dist = sqrt(diff(latitude).^2 + diff(longitude).^2);
Pantelis Saviolakis
Pantelis Saviolakis 2014년 2월 24일
Exactly..It works. THANK YOU. 'Matlab Rules'

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

Community Treasure Hunt

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

Start Hunting!

Translated by