フィルターのクリア

I got this Error :Matrix dimensions must agree

1 回表示 (過去 30 日間)
Mohammed
Mohammed 2012 年 9 月 18 日
Q1: When i input this formula ; f=(4/pi)*sum((1./n)*sin(2*pi*n.*t)) I got this error: Matrix dimensions must agree
Where n=1:2:401 and t=linspace(-0.5,0.5,250)
Q2: f=1/pi+0.5*sin(pi*tau)-2/pi*(cos(pi*n'*tau)/n'.^2-1) tau=linspace(-0.5,0.5,250); n=2:2:106; i get the same error !
Please correct it for me. And show me where are the mistakes

回答 (3 件)

Andrei Bobrov
Andrei Bobrov 2012 年 9 月 18 日
編集済み: Andrei Bobrov 2012 年 9 月 18 日
one way
%W1:
n = (1:2:401).';
t = linspace(-0.5,0.5,250);
f = 4/pi*sum(bsxfun(@times,1./n,sin(2*pi*n*t)));
%W2:
n = (2:2:106).';
tau = linspace(-0.5,0.5,250);
f = 1/pi+bsxfun(@minus,0.5*sin(pi*tau),2/pi*(bsxfun(@rdivide,cos(pi*n*tau),n.^2)-1));
  2 件のコメント
Andrei Bobrov
Andrei Bobrov 2012 年 9 月 18 日
corrected
Jan
Jan 2012 年 9 月 18 日
Mohammed has written [MOVED from answer to comment section]:
But i need 250 variables for t

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


Jan
Jan 2012 年 9 月 18 日
for the expression n .* t the variables n and t must have the same size. Perhaps you want a matrix like, e.g. created by a dyadic product:
n(:) * t
But as long as you do not specify this, n .* t is simply a bug, when the sizes differ or non of them is a scalar.

Mohammed
Mohammed 2012 年 9 月 18 日
Non of answers work !
  1 件のコメント
Jan
Jan 2012 年 9 月 18 日
編集済み: Jan 2012 年 9 月 18 日
Please, Mohammed, do not post comments to answers as answer, but as comment. When you claim, that a suggested method "does not work", be so kind to show the code, the error message or an explanation of the difference between your expectation and the results.
Of course my suggestion will "not work", because I told you, that there is a bug in your code or that you at least did not tell us, what you want to achieve exactly enough. How could this be "working"?!

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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by