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
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.
采纳的回答
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)
coords = [1 5; 3 7]
magnitudes = Catalog(ismember(Catalog(:,1:2),coords,'rows'),3)
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
magnitudes = Catalog(ismember(Catalog(:,1:2),coords,'rows'),3)
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')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dialog Boxes 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!