Downsample and reconstruct a subsection of a vector?

5 次查看(过去 30 天)
Hi all,
I have vectors of lonitude and latitude (and other equally sized metadata vectors) from some geospatial data over a region at a uniform resolution. Within this I have defined an area of interest using a bounding box (geo.FineSamplingBox) defining top left and bottom left coordinates of the area of interest. I have used this to index the points inside and outside this box. The points inside the box I would like to retain the original sampling rate, and the points outside the box I would like to downsample by a factor of 10 (geo.SS_Factor).
I have managed to extract the respective points, but I am unsure how to re-insert them into the original matrix without losing the original order. I have attempted to solve it by appending the fine matrix with the coarse matrix and then sorting them but I am not sure the best way of doing this.
Any thoughts, answers or comments would be greatly appreciated, thank you! Apologies I cannot provide any data - the fine sampled vectors are 1888x1, and the coarse sampled vectors are 1370x1.
Code extract below:
%% ADDED - APPLY COARSE/FINE SUBSAMPLING BASED ON BOUNDING BOX
if geo.BB ==1
FineSampLon = loadedData.Lon > geo.FineSamplingBox(1) & loadedData.Lon < geo.FineSamplingBox(3);
FineSampLat = loadedData.Lat < geo.FineSamplingBox(2) & loadedData.Lat > geo.FineSamplingBox(4);
FineSamp = FineSampLon & FineSampLat;
CoarseSamp = find(loadedData.Lon < geo.FineSamplingBox(1) | loadedData.Lon > geo.FineSamplingBox(3) | loadedData.Lat > geo.FineSamplingBox(2) | loadedData.Lat < geo.FineSamplingBox(4));
if sum(CoarseSamp)>0
PhaseCoarse= downsample(loadedData.Phase(CoarseSamp),geo.SS_Factor);
LatCoarse = downsample(loadedData.Lat(CoarseSamp),geo.SS_Factor);
LonCoarse = downsample(loadedData.Lon(CoarseSamp),geo.SS_Factor);
HeadCoarse = downsample(loadedData.Heading(CoarseSamp),geo.SS_Factor);
IncCoarse = downsample(loadedData.Inc(CoarseSamp),geo.SS_Factor);
PhaseFine = loadedData.Phase(FineSamp);
LatFine = loadedData.Lat(FineSamp);
LonFine = loadedData.Lon(FineSamp);
HeadFine = loadedData.Heading(FineSamp);
IncFine = loadedData.Inc(FineSamp);
end
end
%Reorder lat and lon matrix and apply that to the other matricies?
%Find when lat is above or below the thresholds of the bounding box and
%add coarse sampled data back in??

回答(1 个)

dpb
dpb 2023-1-18
编辑:dpb 2023-1-19
If they're just vectors, I think the simplest is probably the best and likely the quickest...
LO=geo.FineSamplingBox(1); HI=geo.FineSamplingBox(3); % convenient shorthand names
N=geo.SS_Factor;
dataPrime=[decimate(data(:,1:LO),N) data(:,LO+1:HI-1) decimate(data(:,HI:end),N)]; % columns of 2D
dataPrime=[decimate(dataPrime(1:LO,:),N) dataPrime(LO+1:HI-1,:) decimate(dataPrime(HI:end,:),N)]; % rows of 2D
I didn't try to construct it, an alternative would be to create a 2D logical addressing array that matches the areas and uses it as a logical address expression.

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by