multiple number of inputs, two variables, linear regression

so, i need to insert two variables (14 times each) and find the linear regression of those values
i wrote this code :
clear all
clc
n=input('give n:'); %, 's');
x=zeros(n,1); % pinakas nx1
y=zeros(n,1); % pinakas nx1
for i=1:n
x(i)=input(['give x:' num2str(i,3)], 's');
y(i)=input(['give y:' num2str(i,3)], 's');
end
X=mean(x);
Y=mean(y);
b=sum((x-X).*(y-Y))/sum((x-X).*(x-X))
a=Y-b*X
but each time i input two digit number i get this message: "Unable to perform assignment because the left and right sides have a different number of elements."
what am i doing wrong?
thank you

 Accepted Answer

x(i)=input(['give x:' num2str(i,3)], 's');
When you use 's' for input() then it requests a character vector of output. Unless the user happens to enter exactly one character, the result is not going to fit inside x(i) . Furthermore, you later use the x values as numeric, so it seems unlikely that you want to record the characters. I suggest removing the 's' option of input()

More Answers (1)

thank you, i removed num2str(i,30], 's'); as below and i got my result (i think!)
thanks again for answering on such short notice!
n=input('give n ');
x=zeros(n,1);
y=zeros(n,1);
for i=1:n
x(i)=input(['give x']); % num2str(i,3)], 's');
y(i)=input(['give y']); num2str(i,3)], 's');
end
X=mean(x);
Y=mean(y);
b=sum((x-X).*(y-Y))/sum((x-X).*(x-X))
a=Y-b*X

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!