How do I separate negative datas with their row?

First 2 rows contain the long/lat;third row contains the land/water values. I want to separate the files into land and water xyz files for bathymetry use therfore I need the negative values from the 3rd column and their respective rows. I would like to extract the whole row of data containing negative numbers in any of the columns. It has 9135x3 cells of data. Any idea how to do this?

 采纳的回答

Let H be your third column.
idx = H<0 ; % get all negative values logical indices
lon1 = lon(idx) ;
lat1 = lat(idx) ;
H1 = H(idx) ;
If A is your data of size 9135x3.
iwant = A(A(:,3)<0,:) ;

7 个评论

I am new to matlab so please pardon me.
I am getting this error,
Undefined operator '<' for input arguments of type 'table'.
Show us the whole code which gave you error.
idx = SG1<0 ;
lon1 = lon(idx) ;
lat1 = lat(idx) ;
h1 = h(idx) ;
Results = SG1(SG1(:,3)<0,:);
this is what I have right now
How you got SG1, lon, lat; thios is what matters for the error.
H = SG1(:,3); % Land/Water Values
J = SG1(:,1); % Longitude
K = SG1(:,2); % Latitude
idx = H<0 ; <===Undefined operator '<' for input arguments of type 'table'.
lon1 = J(idx) ;
lat1 = K(idx) ;
h1 = H(idx) ;
Results = SG1(SG1(:,3)<0,:);
I am not sure if I am doing this right. Please guide me.
SG1 is my 9135x3 data which I imported as table. Do I need to convert it to an array?
H = SG1.(3); % Land/Water Values
J = SG1.(1); % Longitude
K = SG1.(2); % Latitude
idx = H<0 ;
lon1 = J(idx) ;
lat1 = K(idx) ;
h1 = H(idx) ;
It worked! Thank you for your patience and guidance! @KSSV

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 MATLAB Support Package for USB Webcams 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by