Inside of a for loop. How to call another script lets say (IK.m) as Ik sub every time the loop goes to a new point?
3 views (last 30 days)
%% Inside a for loop. How can I call another script lets say (IK.m) as Ik sub every time the loop goes to a new point?
% I've already calculated the points of the line and created the IK.m program
%IK.m is attached and the calculation of the liner motion is pasted below.
%% Input Data
% Xstart = input(' Please Enter X start point: ');% input is not necessary, the point can be inserted within the code
% Ystart = input(' Please Enter Y start point: ');
% Zstart = input(' Please Enter Z start point: ');
% Xend = input(' Please Enter X end point: ');
% Yend = input(' Please Enter Y end point: ');
% Zend = input(' Please Enter Z end point: ');
% Resolution = input(' Please number of resolution: ');
%% Direct Data
Xstart = 100;
Ystart = 0;
Zstart = 10;
Xend = 200;
Yend = 0;
Zend = 10;
Resolution = 100;
DeltaX = (Xend-Xstart)/Resolution;
DeltaY = (Yend-Ystart)/Resolution;
DeltaZ = (Zend-Zstart)/Resolution;
N = Resolution;
P = 1:N;
X = Xstart + (DeltaX * P);
Y = Ystart + (DeltaY * P);
Z = Zstart + (DeltaZ * P);
fprintf('\n Output: DeltaX = %f and DeltaY = %f \n',DeltaX,DeltaY);
fprintf('\n Position of X & Y: \n \n');
fprintf(' %f \n',X);
fprintf(' %f \n',Y);
fprintf(' %f \n',Z);
grid on; hold on;
plot3(Xstart,Ystart,Zstart,'g.', Xend,Yend,Zend ,'r.','MarkerSize',16)
xlabel('X Axis'); ylabel('Y Axis');zlabel('Z Axis');
Rik on 13 Oct 2021
I don't see how exactly you would end up with 6 values for each point, but if you convert your script to a function, that will make a implementing a loop trivial.
%my guess for the first line of IK.m:
Don't forget to write documentation for this function. It should explain what input it expects, what it does, and what output it will give. Ideally you would also include an example. Make sure you only need to read that whenever you use your function again in three years.