MATLAB saying not enough input arguments.

I am probably missing something completely obvious because I am very new to matlab.
function y = myrowproduct(A, x)
%This function computes the pro
%duct of matrix A by
%vector x row-wise
% define m number of rows here to feed into for loop
[ma,na] = size(A);
[mx,nx] = size(x);
% use if statement to check for proper dimensions
if(na == mx & nx == 1)
y = zeros(ma,1); % initialize y vector for n = 1:ma
y(n) = A(n,:)*x;
else
disp('Dimensions of matrices do not match')
y = [];
end
end

回答 (2 件)

Image Analyst
Image Analyst 2014 年 2 月 18 日

0 投票

Use double &
if (na == mx && nx == 1)

2 件のコメント

Ryan
Ryan 2014 年 2 月 18 日
Ok, I did that. I am getting.
Error in mfile (line 11)
y(n) = A(n,:)*x;
Image Analyst
Image Analyst 2014 年 2 月 18 日
You need
y(n) = A(n,:) .* x';
to multiply the column elements of row n in y by the row elements in the column vector x.

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

Star Strider
Star Strider 2014 年 2 月 18 日

0 投票

Your value of n is undefined. Not to spoil your fun in troubleshooting your code, but you need a for loop:
A = rand(4);
x = rand(4,1);
na = size(A,1);
for n = 1:na
y(n,:) = A(n,:)*x;
end
Adding the colon in the subscript ( y(n,:) = ... ) forces it to be a column vector, as it should be.
Check your code. Right now, you will only get an empty matrix for y.

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2014 年 2 月 18 日

コメント済み:

2014 年 2 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by