How to write single Script for all profiles ?

8 visualizzazioni (ultimi 30 giorni)
Jes
Jes il 2 Set 2025
Risposto: Anmol il 5 Set 2025
The input in my case is the measurement data from a sensor doing spiral scanning. So I have 3D point data (x, y, z) of the surface for different geometries like hemisphere, plane, sphere, and cylinder. The script should preprocess this data (filtering, centering, vertex search), fit the right model (sphere, plane, cylinder, or freeform), and then output the fitted parameters along with residuals. The outcomes I want are both numerical results (fit parameters and errors) and visualizations in 2D cross-sections and 3D surface plots.
  2 Commenti
Rik
Rik il 2 Set 2025

What exactly is your question? Are you trying to write the code in the first place? Are you unsure how to put that code in a function? Or do you want the code to automatically determine the geometry and are you not sure how to start with that?

Your post is an excellent start for the documentation of your function. Just be more explicit about the inputs and outputs and write an example.

Accedi per commentare.

Risposte (1)

Anmol
Anmol il 5 Set 2025
Hi Jes,
I understand that you have measurement data from a sensor doing spiral scanning. The data is 3-Dimensional point data for geometries like sphere, cylinder and plane. The tasks required are:
  1. Preprocess Data (Filtering, Centering and Vertex Search)
  2. Fit the right model (Sphere, Plane or Cylinder)
  3. Output the Fitted Parameters and errors with visualization
Assuming you are looking to write a script for the above functions. Different functions can be written to filter, center the data and to do vertex search. From the pre-processed data, you can then fit and visualize the required model.
This is an example to pre-process the data, assuming you are loading the data from a file path.
STEP 1: Preprocessing the data
This is an example:
% For centering the data.
ptCloud = pointCloud(data); % data contains the loaded points data
centroid = mean(ptCloud.Location, 1);
ptCloud = pointCloud(ptCloud.Location - centroid);
fprintf('Point cloud centered at the origin.\n');
For removing noisy points that are far from their neighbours, which helps to improve the accuracy of model fitting.
% For Statistical Outlier Removal (SOR) Filtering
% - NumNeighbors: The number of nearest neighbours to analyze for each point.
% - Threshold: The standard deviation ratio. A smaller value removes more outliers.
[ptCloud_filtered, ~] = pcdenoise(ptCloud, 'NumNeighbors', 10, 'Threshold', 1.0);
num_removed = ptCloud.Count - ptCloud_filtered.Count;
fprintf('Removed %d outliers using SOR filter.\n', num_removed);
For the vertex search :-
% For vertex Search, using kdTree
kdTree = KDTreeSearcher(ptCloud_filtered.Location);
STEP 2: Fitting the right model and visualization
For example, these commands can be used for ellipsoid and spherical fit:
fobjEllipsoid=ellipsoidalFit(xyz); %Perform ellipse and sphere fits
fobjSphere=sphericalFit(xyz),
[hE,hData]=plot(fobjEllipsoid); %Visualize
hold on
hS=showfit(fobjSphere,'FaceAlpha',0.3,'FaceColor','g');
hold off
legend([hE,hS,hData],'Ellipsoid fit','Sphere fit','XYZ samples','Location','northeast','FontSize',15);
You can refer to the following links for the relevant documentation:
Hope this helps.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by