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

2 次查看(过去 30 天)
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(:)];

采纳的回答

Adam Danz
Adam Danz 2023-3-22
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 个评论
Adam Danz
Adam Danz 2023-3-22
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by