Repeating a function for different values and storing the output in different variables.

13 Ansichten (letzte 30 Tage)
I was wondering if anyone could help me out - I have a subfunction that creates a plane through my 3D model based on 3 points (p0 p1 and p2) and finds the points from the model point cloud on this plane. My output at the end is P, a matrix n x 3 that contains the coordinates for all points on the plane. The function itself works perfectly.
However, would like to rerun that subfunction multiple times for different p0, p1, p2 configurations and store the output for each iteration seperately in P1 P2 P3 etc.
How do I do this?
Thanks!
function points_on_plane
p0 = [ x y z]
p1 = [ x y z]
p2 = [ x y z]
% followed by rest of the function for creating plane and finding points on the plane
% ind - indexes points from x y and z coordinate arrays that are closest to
% the plane
P=[xcoord(ind),ycoord(ind),zcoord(ind)];
end

Akzeptierte Antwort

David Hill
David Hill am 2 Apr. 2021
for k=1:10%however many times you want to run it
P{k}=points_on_plane(p0,p1,p2);%just use a cell array for your output so that you can index into it
end

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by