May the number of decimal point be related with errors in matlab by using inpolygon and ismember functions?

2 views (last 30 days)
busra gogen
busra gogen on 13 May 2022
Commented: busra gogen on 16 May 2022
I am using the inpolygon command to find the points inside 6 different polygons. Althoug it shows 125 points inside in these polygons, it displayed 127 values. Additional two values are founded by ismember command and these values are magnitudes of events respected to their coordinates and It gives error that "Error using horzcat. Dimensions of arrays being concatenated are not consistent.". Is it can be related with the decimals? Also, there are more than 125 points inside these polygons, but command doesn't work accuratley in my opinion. Maybe it was my fault. What should I do with my excel data? I think there is something wrong with my excel sheet but I couldn't figure out. Here is my code. Additionally, I already checked catalog sheet, there is nothing wrong with the column numbers for ismember command so this is why I am thinking about the decimals because before I rounded the coordinates of events, it was displaying more than 125 points inside the polygons but after using the rounded values with 2 decimals, it gived less points but I am sure that there are more than 125 points inside them.
AreaSources=xlsread("MATLAB","AREA");
Catalog=xlsread("MATLAB","guncel");
for i = 1:length(AreaString)
xv1{i} = AreaString{i}(:,2);
yv1{i} = AreaString{i}(:,3);
in1{i}=inpolygon(xq1,yq1,xv1{i},yv1{i});
[in1{i},on1{i}]= inpolygon(xq1,yq1,xv1{i},yv1{i});
NumofeqsinArea1{i}=numel(xq1(in1{i})); % "125 displayed values"
CoordinatesOfEventsforArea1{i}=[xq1(in1{i}) yq1(in1{i})];
MagnitudesOfEventsInAreaSource1{i}= Catalog(ismember(Catalog(:,1:2),CoordinatesOfEventsforArea1{i},'rows'),3); % "127 displayed values???"
YearsOfEventsInAreaSource1{i}= Catalog(ismember(Catalog(:,1:2),CoordinatesOfEventsforArea1{i},'rows'),5);
MonthsOfEventsInAreaSource1{i}= Catalog(ismember(Catalog(:,1:2),CoordinatesOfEventsforArea1{i},'rows'),6);
DaysOfEventsInAreaSource1{i}= Catalog(ismember(Catalog(:,1:2),CoordinatesOfEventsforArea1{i},'rows'),7);
InAreaSource1{i} = [CoordinatesOfEventsforArea1{i}(:,1:2) MagnitudesOfEventsInAreaSource1{i} CoordinatesOfEventsforArea1{i}(:,3:end)];
e1{i}=[DaysOfEventsInAreaSource1{i}(:,1:1) InAreaSource1{i}];
e2{i}=[MonthsOfEventsInAreaSource1{i}(:,1:1) e1{i}];
EventsDateIncludedforArea1{i}=[YearsOfEventsInAreaSource1{i}(:,1:1) e2{i}];
end
  3 Comments
busra gogen
busra gogen on 13 May 2022
I'm sorry for the confusing.
1)There should be 250 points inside in the polygons as I made comment in this line:
NumofeqsinArea1{i}=numel(xq1(in1{i})); % "125 displayed values"
BUT when I want to match the points with their magnitudes which is in this line:
MagnitudesOfEventsInAreaSource1{i}= Catalog(ismember(Catalog(:,1:2),CoordinatesOfEventsforArea1{i},'rows'),3);
it gives 127 magnitudes. I am asking how it is possible? Can be related with the data's decimal points. There is something still wrong with the 125 values because according to my data, there are 250 values. (decimal digits are should be 92.56565656? or 92.57? )
2)Polygons : "AreaString"

Sign in to comment.

Accepted Answer

Voss
Voss on 13 May 2022
"I am asking how it is possible?"
MagnitudesOfEventsInAreaSource1{i} can have more than NumofeqsinArea1{i} elements if Catalog has repeated rows (actually, repeated pairs of elements in the first 2 columns of each row).
I will try to illustrate this using a small example.
First, no repeats in Catalog:
Catalog = reshape(1:12,[],3)
Catalog = 4×3
1 5 9 2 6 10 3 7 11 4 8 12
coords = [1 5; 3 7]
coords = 2×2
1 5 3 7
magnitudes = Catalog(ismember(Catalog(:,1:2),coords,'rows'),3)
magnitudes = 2×1
9 11
Now, Catalog has repeated pairs in its first two columns:
Catalog = Catalog([1:end 1 3 4 1 2],:);
Catalog(5:9,3) = 13:17
Catalog = 9×3
1 5 9 2 6 10 3 7 11 4 8 12 1 5 13 3 7 14 4 8 15 1 5 16 2 6 17
magnitudes = Catalog(ismember(Catalog(:,1:2),coords,'rows'),3)
magnitudes = 5×1
9 11 13 14 16
Due of the repeats in Catalog, coords has 2 rows but magnitudes has 5, because that's how many rows of Catalog(:,1:2) are "members" of coords.
ismember(Catalog(:,1:2),coords,'rows')
ans = 9×1 logical array
1 0 1 0 1 1 0 1 0
  1 Comment
busra gogen
busra gogen on 16 May 2022
Thank you sir, I got your clear example. (1,5) is repeated so it displays two different magnitudes. However, I already checked my excel data and there is no dublicated row, yes there are dublicated coordinates for some events but they are like that:
96.48 23.467 5.7
96.58 22.69 5.8
95.43 23.467 4.0
96.58 21.54 5.0

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!