MATLAB: Problem in functin (y for x)

matlab functionxy

Hy i have a problem in the flowing code (XZData.m function)
function [x,y] = XZData(A,B,C)
x = 0:1:10;
y = (A*x^2)+(B*x)+C;
XY = ['XData', num2str(x), 'yData', num2str(y)];
disp(XY)

Best Answer

Use element-wise exponentiation in the ‘y’ assignment:
y = (A*x.^2)+(B*x)+C;
↑ ← INSERT ‘.’ HERE
function [x,y] = XZData(A,B,C)
x = 0:1:10;
y = (A*x.^2)+(B*x)+C;
XY = ['XData ', num2str(x), ' yData ', num2str(y)];
disp(XY)
end
See the documentation on Array vs. Matrix Operations for details.
Related Question