MATLAB: How tondex Points and Store them all in an Array

arrayindexingmatrix

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).

Best Answer

[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;
Related Question