필터 지우기
필터 지우기

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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by