Problem with code. Error using vertcat

2 ビュー (過去 30 日間)
Claire
Claire 2015 年 3 月 12 日
コメント済み: Star Strider 2015 年 3 月 12 日
Hello, I am having difficulty with a code. Every time I run it, it tells me that I have an error using vertcat. I'm not quite sure how to fix this. Any help is greatly appreciated. The code is provided below:
function a = QuadFit( x,y )
colx=size(x);
coly=size(y);
m=colx;
n=coly;
if m~=n
error('Size of x and y must be equal');
end
%x values summation
sumx=0;
for i=1:m
sumx=sumx+x(i);
end
%x^2 values summation
sumx_2=0;
for i=1:m
sumx_2=sumx_2+(x(i)^2);
end
%x^3 values summation
sumx_3=0;
for i=1:m
sumx_3=sumx_3+(x(i)^3);
end
%x^4 values summation
sumx_4=0;
for i=1:m;
sumx_4=sumx_4+(x(i)^4);
end
%y values summation
sumy=0;
for i=1:m
sumy=sumy+y(i);
end
%x*y values summation
sumxy=0;
for i=1:m
sumxy=sumxy+(x(i)*y(i));
end
%(x^2)*y values summation
sumx_2y=0;
for i=1:m
sumx_2y=sumx_2y+((x(i)^2)*y(i));
end
a=[sumx_2 sumx_3 sumx_4 sumx_2y;sumx sumx_2 sumx_3 sumxy;n sumx sumx_2 sumy];
a=rref(a);
a1=a(1,4);
a2=a(2,4);
a3=a(3,4);
end
The error is occurring is this line:
a=[sumx_2 sumx_3 sumx_4 sumx_2y;sumx sumx_2 sumx_3 sumxy;n sumx sumx_2 sumy];

採用された回答

Star Strider
Star Strider 2015 年 3 月 12 日
If you want the column size only of ‘x’ and ‘y’, you have to be specific with the size function.
Change the ‘colx’ and ‘coly’ assignments to:
colx=size(x,2);
coly=size(y,2);
and it works!
  2 件のコメント
Claire
Claire 2015 年 3 月 12 日
Thank you so much!
Star Strider
Star Strider 2015 年 3 月 12 日
My pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by