Azzera filtri
Azzera filtri

How to get the rows and columns from a matrix which do not fall into particular criteria?

2 visualizzazioni (ultimi 30 giorni)
Hello,
My data comprises of a matrix.
% Data1 = 25000 x 30 double
After running some lines of code I got my Data2 (from Data1 using logical indexing etc) which is now
% Data2 = 10000 x 30 double
However I also want to do some statistics on the rest 15000 x 30 dataset. I guess it's quite simple but I can't figure out how to get this 15000 x 30 matrix from Data1. After doing logical indexing etc I got Data2, how to get the remaining matrix which do not fall into my particular criteria for Data2 i.e, 15000x30? Thank you

Risposta accettata

Dyuman Joshi
Dyuman Joshi il 16 Mar 2023
Use negation on the logical indexing -
x = 0:0.01:10;
y = [sin(x); cos(x)];
%Get columns of y in which
%first row is less than or equal to -0.25
idx = y(1,:)<=-0.25;
data1 = y(:,idx)
data1 = 2×297
-0.2555 -0.2652 -0.2748 -0.2844 -0.2940 -0.3035 -0.3131 -0.3225 -0.3320 -0.3414 -0.3508 -0.3601 -0.3694 -0.3787 -0.3880 -0.3971 -0.4063 -0.4154 -0.4245 -0.4335 -0.4425 -0.4515 -0.4604 -0.4692 -0.4780 -0.4868 -0.4955 -0.5042 -0.5128 -0.5213 -0.9668 -0.9642 -0.9615 -0.9587 -0.9558 -0.9528 -0.9497 -0.9466 -0.9433 -0.9399 -0.9365 -0.9329 -0.9293 -0.9255 -0.9217 -0.9178 -0.9137 -0.9096 -0.9054 -0.9011 -0.8968 -0.8923 -0.8877 -0.8831 -0.8783 -0.8735 -0.8686 -0.8636 -0.8585 -0.8534
%Get the data which doesn't fall into that category
data = y(:,~idx)
data = 2×704
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0699 0.0799 0.0899 0.0998 0.1098 0.1197 0.1296 0.1395 0.1494 0.1593 0.1692 0.1790 0.1889 0.1987 0.2085 0.2182 0.2280 0.2377 0.2474 0.2571 0.2667 0.2764 0.2860 1.0000 1.0000 0.9998 0.9996 0.9992 0.9988 0.9982 0.9976 0.9968 0.9960 0.9950 0.9940 0.9928 0.9916 0.9902 0.9888 0.9872 0.9856 0.9838 0.9820 0.9801 0.9780 0.9759 0.9737 0.9713 0.9689 0.9664 0.9638 0.9611 0.9582
  4 Commenti
Zhou Ci
Zhou Ci il 16 Mar 2023
Here is my complete code:
% Data1 = 25000X30
Lat=Data1(:,1);
Lon=Data1(:,2);
land = shaperead('landareas', 'UseGeoCoords', true);
land_flags = zeros(length(Lat),1);
for i = 1 : size(land,1)
Lat_land = land(i).Lat;
Lon_land = land(i).Lon;
in1 = inpolygon(Lat(:),Lon(:),Lat_land,Lon_land);
land_flags = land_flags + in1;
end
Data1 = Data1(land_flags == 0,:);
Data2 = real(Data1); % 10000x30
I also want the remaining 'Data3' (15000x30) from the Data1 dataset.
Dyuman Joshi
Dyuman Joshi il 16 Mar 2023
Lat=Data1(:,1);
Lon=Data1(:,2);
land = shaperead('landareas', 'UseGeoCoords', true);
land_flags = zeros(length(Lat),1);
for i = 1 : size(land,1)
Lat_land = land(i).Lat;
Lon_land = land(i).Lon;
in1 = inpolygon(Lat(:),Lon(:),Lat_land,Lon_land);
land_flags = land_flags + in1;
end
idx = land_flags == 0:
Data1 = Data1(idx,:);
Data2 = real(Data1); % 10000x30
Data3 = Data1(~idx,:)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Tables in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by