Calculate the coordinates of nodes in a plot3
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alberto Acri
am 12 Nov. 2022
Kommentiert: Chris
am 13 Nov. 2022
Hi. I would like to know how to calculate the coordinates of the nodes (x,y,z coordinates) and the total number of nodes in this figure. Attached code and figure. Thanks!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1190393/image.png)
0 Kommentare
Akzeptierte Antwort
Chris
am 12 Nov. 2022
This is one figure in the x-y plane. The z coordinates should be constant, wherever you choose to set z. If you had several images for a stack, you could use code.m as intended.
imageArray = im2uint8(imread('figure.png'));
imagesc(imageArray)
CoordinateMatrix = pic2points(imageArray);
totalNodes = size(CoordinateMatrix,1)
z = 1;
coordinateMatrix = [CoordinateMatrix, z.*ones(totalNodes,1)];
4 Kommentare
Chris
am 13 Nov. 2022
For plot3, the third method is best. However, you have introduced a new coordinate_matrix_1, which is overwritten with each loop. Delete that. Additionally, you will need to initialize the empty matrix before the loop.
coordinate_matrix = [];
for k = %...
%...
temp_matrix = [coordinate_x, coordinate_y, coordinate_z];
coordinate_matrix = [coordinate_matrix; temp_matrix];
end
totalNodes = size(coordinate_matrix, 1);
If you only want the total number of nodes for the entire stack, you can move the "totalNodes" calculation to after the end of the loop.
For the cell array, you can calculate the number of nodes with this:
totalNodes = size(cat(1,coordinate_matrix{:}),1);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operators and Elementary Operations 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!