How to Index Points and Store them all in an Array
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tom
am 26 Okt. 2018
Kommentiert: Tom
am 10 Nov. 2018
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 Kommentare
Walter Roberson
am 27 Okt. 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.
Akzeptierte Antwort
Walter Roberson
am 27 Okt. 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 Kommentare
Walter Roberson
am 29 Okt. 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))];
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!