# How to extract the data using inpolygon function ?

18 views (last 30 days)
aa on 25 Jan 2021
Commented: aa on 25 Jan 2021
Hi everyone,
May some one help me here ...
I have data in three colums. (1) x-coordinate; (2) y-coordinate; and (3) z-value (parametere) of data length (55000 data points: I reduce the file size due to limit of 5 MB) I required to extarct the z-values lying inside the polygon.
My scripit did not work for the above mentioned purpose. May someone help me how to handle this data and simple script attched here.
clear all
clc
for i=1:length(data)
x = data(:,1) ; y = data(:,2) ; z = data(:,3 ) ;
xVertices = [-116.8, -116.7, -116.45, -116.7];
yVertices = [33.55, 33.40, 33.70, 33.85];
idx(i) = inpolygon(x(i), y(i), xVertices, yVertices);
iwant(i) = [ z(idx )] ;
end
Thank you.

Cris LaPierre on 25 Jan 2021
Consult the inpolygon documentation page. You can probably do this without the for loop, as inpolygon can query a vector of points at once.
Here is an example from the linked page.
% Define polygon
L = linspace(0,2*pi,6);
xv = cos(L)';
yv = sin(L)';
% Define points to query
xq = randn(250,1);
yq = randn(250,1);
% Find points inside polygon
[in,on] = inpolygon(xq,yq,xv,yv);
% Visualize results
figure
plot(xv,yv) % polygon
axis equal
hold on
plot(xq(in),yq(in),'r+') % points inside
plot(xq(~in),yq(~in),'bo') % points outside
hold off aa on 25 Jan 2021
Thank you very much this serve for my purpose.
{"ft_lang_label":"__label__en","ft_lang_prob":0.7042734,"math_prob":0.994899,"size":1585,"snap":"2021-43-2021-49","text_gpt3_token_len":484,"char_repetition_ratio":0.1030993,"word_repetition_ratio":0.0,"special_character_ratio":0.32996845,"punctuation_ratio":0.1983471,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98618484,"pos_list":[0,1,2],"im_url_duplicate_count":[null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-07T16:30:30Z\",\"WARC-Record-ID\":\"<urn:uuid:b5daa591-17ee-473f-ba33-a4985dc410f1>\",\"Content-Length\":\"130976\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:4fcb7c4c-028d-47a1-823a-9daa07f1f9e9>\",\"WARC-Concurrent-To\":\"<urn:uuid:65a96dba-a613-4e75-81c4-b78a05f797f4>\",\"WARC-IP-Address\":\"23.218.145.211\",\"WARC-Target-URI\":\"https://nl.mathworks.com/matlabcentral/answers/726568-how-to-extract-the-data-using-inpolygon-function?s_tid=prof_contriblnk\",\"WARC-Payload-Digest\":\"sha1:X363ADODRCC3MILMFJMKTCUF2MUMUX7Q\",\"WARC-Block-Digest\":\"sha1:BSD55PS45SFFFOLPWQB5G5HEN6OGIWGC\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964363400.19_warc_CC-MAIN-20211207140255-20211207170255-00074.warc.gz\"}"}