Dear all,
My file have 3 column and more than hundred line..First column represent latitude, second longitude and lastly sea level. My plan is to average the sea level data based on specific range of latitude and longitude..I try design the program but still not work..Let say my file name is 200012.txt and i try to extract sea level data in range of (2<lat<3) & (95<lon<97)..But still not success. Help me
f=load('200012.txt'); lat=f(:,1); lon=f(:,2); sla=f(:,3);
x=sla(find((2<lat<3) & (95<lon<97)))

 채택된 답변

Chandra Kurniawan
Chandra Kurniawan 2011년 12월 25일

2 개 추천

Hello,
I have a text file formated :
1 90 100
1 96 101
1 95 102
2 91 103
2 96 104
1 89 105
3 87 106
3 96 107
2 90 108
4 97 109
2 76 110
And Here the script :
clear; clc;
f = load('200012.txt');
lat = f(:,1);
lon = f(:,2);
sla = f(:,3);
%x = sla(find((2<lat<3) & (95<lon<97)))
r = sla(find(lat >=2 & lat <= 3 & lon >=95 & lon <= 97))
The Result :
r =
104
107

댓글 수: 7

joo tan
joo tan 2011년 12월 25일
also work..but,how to spacing for lat and long 0.25 to find the sla value.
Thanks
joo tan
joo tan 2011년 12월 25일
i try to design back the program to make loop and spacing 0.25..but not work..any idea??
f=load('200012.txt');
lat=f(:,1);
lon=f(:,2);
sla=f(:,3);
for i=2:0.25:14.75
j=2.25:0.25:15
k=95:0.25:125.75
l=95.25:0.25:126
r = sla(find(lat >=(i) & lat <= (j) & lon >=(k) & lon <= (l)))
a=mean(r)
end
Chandra Kurniawan
Chandra Kurniawan 2011년 12월 25일
I don't understand what you want to do.
Did you mean you need to find lat at 2.00, 2.25, 2.50, ... , 14.75??
joo tan
joo tan 2011년 12월 25일
i meant, to find the sla value in the specific range lat and lon but the lat and lon changes 0.25..let say first operation is to find and mean the sla value in the range
2=<lat<=2.25 and 95=<lon<=95.25
second operation is
2.25=<lat<=2.5 and 95.25=<lon<=95.5
and it changes until lat=15 and lon=126
i try use this program but the processing non-stop..i dont know why..the file size become more big
f=load('200012.txt');
lat=f(:,1);
lon=f(:,2);
sla=f(:,3);
F='mean.TXT';
for i=2:0.25:14.75;
for j=2.25:0.25:15;
for k=95:0.25:125.75;
for l=95.25:0.25:126;
r = sla(find(lat >=(i) & lat <= (j) & lon >=(k) & lon <= (l)));
b=mean(r);
fid=fopen(F,'a');
fprintf(fid,'\n%15.6f%15.6f%15.6f%15.6f%15.6f%15.6f\n',b);
fclose(fid);
end
end
end
end
if you want try run, this is link for the file
http://www.mediafire.com/file/jy6t6yjs9jxpeno/200012.txt
joo tan
joo tan 2011년 12월 25일
i meant, to find the sla value in the specific range lat and lon but the lat and lon changes 0.25..let say first operation is to find and mean the sla value in the range
2=<lat<=2.25 and 95=<lon<=95.25
second operation is
2.25=<lat<=2.5 and 95.25=<lon<=95.5
and it changes until lat=15 and lon=126
i try use this program but the processing non-stop..i dont know why..the file size become more big
f=load('200012.txt');
lat=f(:,1);
lon=f(:,2);
sla=f(:,3);
F='mean.TXT';
for i=2:0.25:14.75;
for j=2.25:0.25:15;
for k=95:0.25:125.75;
for l=95.25:0.25:126;
r = sla(find(lat >=(i) & lat <= (j) & lon >=(k) & lon <= (l)));
b=mean(r);
fid=fopen(F,'a');
fprintf(fid,'\n%15.6f%15.6f%15.6f%15.6f%15.6f%15.6f\n',b);
fclose(fid);
end
end
end
end
if you want try run, this is link for the file
http://www.mediafire.com/file/jy6t6yjs9jxpeno/200012.txt
Chandra Kurniawan
Chandra Kurniawan 2011년 12월 25일
No, I think you can't do that.
i = 2 : 0.25 : 15; %size 1x53
j = 95 : 0.25 : 126; %size 1x125
Coz, the size of i and j must be same.
Mitson Monteiro
Mitson Monteiro 2013년 12월 6일
suppose if i want the answer as r = 2 96 104 3 96 107 what will it be

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

추가 답변 (4개)

Chandra Kurniawan
Chandra Kurniawan 2011년 12월 25일

1 개 추천

If size of i and j are same, then
f = load('200012.txt');
lat = f(:,1);
lon = f(:,2);
sla = f(:,3);
i = 2 : 0.25 : 15;
j = 95 : 0.25 : 126;
for x = 1 : numel(i)-1
r = sla(find(lat >=i(x) & lat <= i(x+1) & lon >= j(x) & lon <= j(x+1)))
b = mean(r)
end
This code I just use x = 1 : 53

댓글 수: 1

joo tan
joo tan 2011년 12월 25일
tq chandra...i am sorry..i mistake give wrong information..the true is to find the sla value in the specific range lat and lon but the lat and lon changes 0.25..let say first operation is to find and mean the sla value in the range
2=<lat<=2.25 and 95=<lon<=95.25
second operation is
2=<lat<=2.25 and 95.25=<lon<=95.5
third
2=<lat<=2.25 and 95.5=<lon<=95.75
.............until the longitude 126..after that, the operation will continue with
latitude 2.25 and longitude same as above..it is like to grid bin by bin..the size of each bin 0.25
But, tq because your idea is good..i will try to find solution..I am so sorry about this..take your time

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

joo tan
joo tan 2011년 12월 25일

1 개 추천

already solve problem..thanks
f = load('D1.ASC'); lat = f(:,1); lon = f(:,2); sla = f(:,3); i=2:0.25:15 j = 95 : 0.25 : 126; F='meanBIN.TXT' for y=1:52 for x = 1 : 124 r1 = sla(find(lat >i(y) & lat <= i(y+1) & lon >= j(x) & lon <= j(x+1))) b = mean(r1)
fid=fopen(F,'a'); fprintf(fid,'\n%15.6f%15.6f%15.6f%15.6f%15.6f%15.6f\n',i(y+1),j(x+1),b); fclose(fid); end end
Image Analyst
Image Analyst 2011년 12월 25일

0 개 추천

Try something like this (I didn't test it):
rowsToAverage = lat>2 & lat<3 & lon>95 & lon<97;
meanValue = mean(sla(rowsToAverage));

댓글 수: 1

joo tan
joo tan 2011년 12월 25일
yes..it is works..but my problem is, i want to make the latitude and longitude spacing 0.25..

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

joo tan
joo tan 2011년 12월 25일

0 개 추천

yes..it is works..but my problem is, i want to make the latitude and longitude spacing 0.25..

카테고리

도움말 센터File Exchange에서 Geographic Plots에 대해 자세히 알아보기

질문:

2011년 12월 25일

댓글:

2013년 12월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by