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

1 次查看(过去 30 天)
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 个评论
Jan
Jan 2022-5-13
"Althoug it shows 125 points inside in these polygons, it displayed 127 values." - please explain, what this sentence means. What is the difference between showing and displaying?
"Error using horzcat. Dimensions of arrays being concatenated are not consistent." - please post the complete error message which explains, in which line the error occurs.
"Is it can be related with the decimals?" - With which decimals?
"but command doesn't work accuratley in my opinion" - please elaborate this. I cannot guess, what it means.
"I think there is something wrong with my excel sheet but I couldn't figure out." - please read: https://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
The readers cannot guess, what "AreaString" is.
Why do you call inpolygone twice?
in1{i} = inpolygon(xq1,yq1,xv1{i},yv1{i});
[in1{i},on1{i}] = inpolygon(xq1,yq1,xv1{i},yv1{i});
The value of numel(xq1(in1{i})) is the same value as numel(in1{i}).
Avoid names as "CoordinatesOfEventsforArea1" or "MagnitudesOfEventsInAreaSource1". They contain too many characters such that the reading isimpeded seriously. Write the code much leaner, because this supports the reading. And by the way, even a question is easier to read, if it is not one big block of text.
busra gogen
busra gogen 2022-5-13
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"

请先登录,再进行评论。

采纳的回答

Voss
Voss 2022-5-13
"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 个评论
busra gogen
busra gogen 2022-5-16
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by