How to Index Points and Store them all in an Array
3 views (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 27 Oct 2018
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.
Accepted Answer
Walter Roberson
on 27 Oct 2018
[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 Comments
Walter Roberson
on 29 Oct 2018
[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))];
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!