MATLAB Answers

Zoe
0

Self-written function does not work when changing input names

Asked by Zoe
on 21 May 2018
Latest activity Commented on by Ameer Hamza
on 21 May 2018
I wrote a function shown below. When I want to enter my input (xnew,ynew) instead of (x,y) , this function would not work. I understand the reason (because my code specifies (x,y)), but do not know how to fix it. Please help. Thank you!
function rline(x,y)
%syntax:
% rline(x,y)
line(x, y, 'Color', 'r', 'LineStyle', '--', 'LineWidth', 2)

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Ameer Hamza
on 21 May 2018
Edited by Ameer Hamza
on 21 May 2018
 Accepted Answer

Have you defined xnew and ynew before calling the function rline(). The name of input to the function at the definition and calling time does need to be same. Try this
xnew = 1:10;
ynew = xnew.^2;
rline(xnew, ynew);

  2 Comments

Sign in to comment.