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?
4 views (last 30 days)
Show older comments
%% 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;
%% Equations
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);
%% Display
fprintf('\n Output: DeltaX = %f and DeltaY = %f \n',DeltaX,DeltaY);
fprintf('\n Position of X & Y: \n \n');
disp('X data:')
fprintf(' %f \n',X);
fprintf('\n');
disp('Y data:')
fprintf(' %f \n',Y);
disp('Z data:')
fprintf(' %f \n',Z);
%% Plot
figure
axis square
plot3(X,Y,Z,'bp-','lineWidth',1,'MarkerSize',3,'MarkerEdge','g','MarkerFace','y')
grid on; hold on;
plot3(Xstart,Ystart,Zstart,'g.', Xend,Yend,Zend ,'r.','MarkerSize',16)
xlabel('X Axis'); ylabel('Y Axis');zlabel('Z Axis');
title('Linear Motion')
2 Comments
Accepted Answer
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:
function Eightsols=IK(epx,epy,epz)
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.
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!