내가 MATLAB에 here 주어진 C++ 코드를 변환을 시도하고 다음 C++ 프로그램에서 점을 반복하는 것이 쉽기 때문에MATLAB에서 좌표 행렬을 반복하는 가장 좋은 방법은 무엇입니까?
// Implementation of Andrew's monotone chain 2D convex hull algorithm.
// Asymptotic complexity: O(n log n).
// Practical performance: 0.5-1.0 seconds for n=1000000 on a 1GHz machine.
#include <algorithm>
#include <vector>
using namespace std;
typedef int coord_t; // coordinate type
typedef long long coord2_t; // must be big enough to hold 2*max(|coordinate|)^2
struct Point {
coord_t x, y;
bool operator <(const Point &p) const {
return x < p.x || (x == p.x && y < p.y);
}
};
// 2D cross product of OA and OB vectors, i.e. z-component of their 3D cross product.
// Returns a positive value, if OAB makes a counter-clockwise turn,
// negative for clockwise turn, and zero if the points are collinear.
coord2_t cross(const Point &O, const Point &A, const Point &B)
{
return (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
}
// Returns a list of points on the convex hull in counter-clockwise order.
// Note: the last point in the returned list is the same as the first one.
vector<Point> convex_hull(vector<Point> P)
{
int n = P.size(), k = 0;
vector<Point> H(2*n);
// Sort points lexicographically
sort(P.begin(), P.end());
// Build lower hull
for (int i = 0; i < n; i++) {
while (k >= 2 && cross(H[k-2], H[k-1], P[i]) <= 0) k--;
H[k++] = P[i];
}
// Build upper hull
for (int i = n-2, t = k+1; i >= 0; i--) {
while (k >= t && cross(H[k-2], H[k-1], P[i]) <= 0) k--;
H[k++] = P[i];
}
H.resize(k);
return H;
}
은 좀 문제가 있어요. MATLAB에서 같은 작업을하고 싶지만 한 번에 주어진 인덱스에서 하나의 특정 값 대신 한 번에 포인트 (x와 y 좌표 모두)를 한 번에 가져오고 싶습니다.
내가 현재로서는 다음 사용하고 좌표의 매트릭스를 생성하려면 -x = randi(1000,100,1);
y = randi(1000,100,1);
points = [x,y];
감사합니다. 내 게시물을 약간 업데이트했습니다. 당신의 대답은 그것을 견뎌 낼 수 있습니까? 또한, 당신이 "매트릭스 C 열 2 행 M으로"무슨 뜻인지 확실하지 않다 – sj22
하려고 M = [x; y] – dzada
나는 아직 이것을 시도하고있다. 빨리 시도하고 여기에서 업데이트 할 것입니다. 다시 한번 감사드립니다. – sj22