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

2 vues (au cours des 30 derniers jours)
MAT NIZAM UTI
MAT NIZAM UTI le 22 Mar 2023
Commenté : MAT NIZAM UTI le 23 Mar 2023
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(:)];

Réponse acceptée

Adam Danz
Adam Danz le 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 commentaires
Adam Danz
Adam Danz le 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.
MAT NIZAM UTI
MAT NIZAM UTI le 23 Mar 2023
Thank you Adam Danz, it work !!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by