Repeating a function for different values and storing the output in different variables.
15 次查看(过去 30 天)
显示 更早的评论
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
2 个评论
Stephen23
2021-4-2
"Repeating a function for different values and storing the output in different variables."
Use indexing:
采纳的回答
David Hill
2021-4-2
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!