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

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 31 Mai 2012

1 Stimme

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

1 Kommentar

Andrew
Andrew am 31 Mai 2012
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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by