You need to add ‘no_of_points’ as an argument to your ‘findCoodinates’ function. You also need to subscript ‘y’ in it, to return a vector rather than a single value.
slope = input('\nEnter the slope:');
y_intercept = input('\nEnter the y_intercept:');
no_of_points = input('\nEnter no_of_points:');
[x,y] = findCoodinates(slope,y_intercept,no_of_points);
plot(x,y, 'ko-');
xlabel('x-axis');
ylabel('y-axis');
legend('First Graph');
axis([0 20 -5 30])
function [x,y] = findCoodinates(m,b,no_of_points)
for i = 1:no_of_points
x(i) = i;
y(i) = x(i)*m + b;
end
end
With those changes, your code worked when I ran it.
Best Answer