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(:)];
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!