HELP WITH CODE Please help!
Show older comments
'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
Accepted Answer
More Answers (0)
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!