MATLAB: How to pass an output from a function to be processed in another function

inputoutput

So i have a function that inputs coordinates and plots a line
function linetranslation(xa,ya,xb,yb)
if nargin == 0
xa = input('First X Coordinate : ');
ya = input('First Y Coordinate : ');
xb = input('Second X Coordinate : ');
yb = input('Second Y Coordinate : ');
end
clf;
hold on;
axis([-10 10 -10 10]);
if xa==xb
if ya<yb
for yi=ya:0.01:yb;
xi=yi+xa-yi;
plot(xi,yi);
end
else
for yi=ya:-0.01:yb;
xi=yi+xa-yi;
plot(xi,yi);
end
end
else
m=(yb-ya)/(xb-xa);
if xa<xb
for xi=xa:0.01:xb;
yi=m*(xi-xa)+ya;
plot(xi,yi);
end
else
for xi=xa:-0.01:xb;
yi=m*(xi-xa)+ya;
plot(xi,yi);
end
end
end
end
the question is how can i pass xi & yi to another function that processes it further
a little idea here, i have tried adding to the first function
function [xi, yi] = linetranslation(xa,ya,xb,yb)
and adding the code below
function Translate(x,y)
>>>here [xi , yi] = linetranslation(xa,ya,xb,yb);
if nargin == 0
% Check the number of input arguments (nargin)
x = input('Translate X: ');
y = input('Translate Y: ');
end
hold on;
axescenter
axis([-10 10 -10 10]);
plot(xi+x,yi+y);
but it returns xa undefined, on the other hand i need xi and yi to be passed
thanks in advance
UPDATE
i have tried putting
[xi,yi] = translasigaris;
below
function translate(x,y)
but
if nargin == 0
xa = input('First X Coordinate : ');
ya = input('First Y Coordinate : ');
xb = input('Second X Coordinate : ');
yb = input('Second Y Coordinate : ');
end
returns as an infinite loop.

Best Answer

If you want to make ‘xi’ and ‘yi’ available to other functions, the easiest way is to have your ‘linetranslation’ function output them.
Change your original function statement to:
function [xi,yi] = linetranslation(xa,ya,xb,yb)
When you then call it such as in this statement:
[xi,yi] = linetranslation(xa,ya,xb,yb);
‘xi’ and ‘yi’ (by whatever variable names you want to assign them to) will be available in your workspace.