HELP WITH CODE Please help!

'GPSData' is a 731x3 matrix of latitude, longitude, and data columns. 'Plot_Corners' is a 32x9 matrix, where the first column is a plot number, and the next 8 columns are latitude and longitude for each corner of that plot. I'm trying to write a fairly simple program that creates a bin of each plot (from 'Plot_Corners') and then searches the 'GPSData' file for data associated with a pair of coordinates that are within xyz bin. I want to assign a plot number to each datum according to its lat/lon. The following code iterates, but returns all zeros in the Output matrix. Any suggestions??
t=cputime;
format long;
GPS_yield=importdata('GPS_yield.txt');
GPSData=GPS_yield.data;
plots1=importdata('GPS_HorizPlot.txt');
Plot_Corners=plots1.data;
unqPlotID=unique(Plot_Corners(:,1));
Output = zeros(length(GPSData),2); % output matrix (plot no, observation no, yield)
for i = 1:length(Plot_Corners)
latmin(1,1)=Plot_Corners(i,6);
latmin(1,2)=Plot_Corners(i,8);
latmax(1,1)=Plot_Corners(i,2);
latmax(1,2)=Plot_Corners(i,4);
lonmin(1,1)=Plot_Corners(i,7);
lonmin(1,2)=Plot_Corners(i,9);
lonmax(1,1)=Plot_Corners(i,3);
lonmax(1,2)=Plot_Corners(i,5);
for j = 1:length('GPSData')
if GPSData(j,1)>min(latmin) && GPSData(j,1)<max(latmax) && ...
GPSData(j,2)>min(lonmin) && GPSData(j,2)<max(lonmax);
Output(j,1) = PlotCorners(i,1);
Output(j,2) = GPSData(j,3);
end
end
end

 채택된 답변

Walter Roberson
Walter Roberson 2012년 5월 31일

1 개 추천

length('GPSData') is 7 as there are 7 characters in the string 'GPSData'
You probably did not want the apostrophes there.

댓글 수: 1

Andrew
Andrew 2012년 5월 31일
Thank you for looking this through. That was part of the problem! I don't know how I didn't catch that in the first place, or why they were added.
Sometimes you just need a second pair of eyes to look something through.
Thank you!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by