フィルターのクリア

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

1 回表示 (過去 30 日間)
MAT NIZAM UTI
MAT NIZAM UTI 2023 年 3 月 22 日
コメント済み: MAT NIZAM UTI 2023 年 3 月 23 日
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.
MAT NIZAM UTI
MAT NIZAM UTI 2023 年 3 月 23 日
Thank you Adam Danz, it work !!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by