How to Index Points and Store them all in an Array
조회 수: 3 (최근 30일)
이전 댓글 표시
I am working with a surface on which I place an arbitrary number of nodes. The points are indexed in spherical polar coordinates via a formula for each coordinate (plus 2 points at the poles). Is there a simple way that I can set out the formulae with MATLAB, choose the index number I would like to go up to and then have the coordinates for each node placed one by one into the columns of a matrix (so the first row would be the theta coordinates for the position vectors of all the nodes, and so on with the phi coordinates for the nodes on the second row and the radial coordinates on the third row).
댓글 수: 2
Walter Roberson
2018년 10월 27일
That would depend upon the available formula, whether index is a parameter to it. If only the coordinates are input the formula then it would depend upon whether there is a good way to calculate the coordinates from the index number, or an effective way to generate enough of the coordinates to determine the index order.
채택된 답변
Walter Roberson
2018년 10월 27일
[i, j] = ndgrid(1:N_theta, 1:N_phi);
theta = i .* pi ./ (N_theta + 1);
phi = 2 .* pi .* (j-1) ./ N_phi;
r = 1;
coords = [theta(:), phi(:)];
coords(:,3) = r;
댓글 수: 3
Walter Roberson
2018년 10월 29일
[i, j] = ndgrid(1:N_theta, 1:N_phi);
theta = i .* pi ./ (N_theta + 1);
phi = 2 .* pi .* (j-1) ./ N_phi;
r = 1;
b = [theta(:).'; phi(:).'; r * ones(1,numel(theta))];
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!