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 ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by