If all points are equal then
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi everyone,
I have a cell with different arrays. The arrays contains different matrices (for example 72x2 double, 5x2 double, or 3x2double).
Now I want to have to if clauses. The first on is, that if the matrice is smaller then 5x2 a logical 0 results.
The same should happen when all entries of the first column of the matrice are equal to each other or when all entries of the second column are equal to each other.
How can I reach this?
for ii=1:length(xLoc)
for kk=1:length(area)
if length(points{kk}(:,1))<5 %5
in(kk)=false;
elseif points{kk}(:,2)==%equal to each other
in(kk)=false;
elseif points{kk}(:,1)==%equal to each other
else
edges = convhull(points{kk}(:,1),points{kk}(:,2));
in(kk) = inpolygon(xLoc(ii),yLoc(ii),points{kk}(edges,1),points{kk}(edges,2)); % true if VortexLoc is inside area
end
end
end
Thanks for your help!!
댓글 수: 0
답변 (1개)
Yazan
2021년 7월 1일
% generate 3 matrices for a demo
A1 = randn(72,2);
A2 = randn(5,2);
A3 = randn(3, 2);
% generate a structure
s = {A1, A2, A3};
% 3 logical statement
f1 = cellfun(@(x) size(x,1)<5, s);
f2 = cellfun(@(x) all(x(:,1)==x(1,1)), s);
f3 = cellfun(@(x) all(x(:,2)==x(1,2)), s);
% or merge f1 and f2 and f3 in one logical statment
% f4 = f1 or f2 or f3
f4 = cellfun(@(x) size(x,1)<5 | all(x(:,1)==x(1,1)) | all(x(:,2)==x(1,2)), s);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!