Extract multiple data from desirable X and Y of (X,Y,Data)

2 views (last 30 days)
Hi I have a data in .asc file that arrange in Latitude, Longitude, Data
The original data for Latitude bounded from -80.3280 to 87.9610 (not in order) - as in the attach file
The original data for Longitude bounded from -179.9980 to 179.9960 (not in order) - as in the attach file
I want to extract the 'Data' with respect to Latitude and Longitude in the range of Latitude (0.000 - 14.000) and Longitude (95.000 - 126.000), so the final product only consist of [Latitude:Longitude:Data] that bounded in the range of Latitude (0.000 - 14.000) and Longitude (95.000 - 126.000).
Here I am showing you my coding. But I really stuck during the extraction, cause I dont have any clue on how to extract the data.
clear all
clc
ncfile = 'SM_REPR_MIR_OSUDP2_20150101T205140_20150101T214459_700_200_1.nc' ; % nc file name
% To get information about the nc file
ncinfo(ncfile)
% % to display nc file
ncdisp(ncfile)
% % to read a vriable 'var' exisiting in nc file
SSS = ncread(ncfile,'SSS_corr') ;
Lat = ncread(ncfile, 'Latitude');
Lon = ncread(ncfile, 'Longitude');
% SSS1 = SSS(1:end);
% Lat1 = Lat (1:end);
% Lon1 = Lon (1:end);
Data = [Lat(:),Lon(:),SSS(:)];

Accepted Answer

Adam Danz
Adam Danz on 22 Mar 2023
Logical indexing is all you need.
The last line removes any rows of table T that are not without the Lat/Lon bounds.
T = readtable('Data.xlsx')
isInLat = T.Latitude >= 0 & T.Latitude <= 14;
isInLon = T.Longitude >= 95 & T.Latitude <= 126;
T(~(isInLat & isInLon),:) = []
  3 Comments
Adam Danz
Adam Danz on 22 Mar 2023
T is a table in my demo. T appears to be a structure in your version. The first line of my solution reads in your data as a table.

Sign in to comment.

More Answers (0)

Categories

Find more on Discrete Data Plots 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!