Filter löschen
Filter löschen

I got this Error :Matrix dimensions must agree

1 Ansicht (letzte 30 Tage)
Mohammed
Mohammed am 18 Sep. 2012
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

Antworten (3)

Andrei Bobrov
Andrei Bobrov am 18 Sep. 2012
Bearbeitet: Andrei Bobrov am 18 Sep. 2012
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 Kommentare
Andrei Bobrov
Andrei Bobrov am 18 Sep. 2012
corrected
Jan
Jan am 18 Sep. 2012
Mohammed has written [MOVED from answer to comment section]:
But i need 250 variables for t

Melden Sie sich an, um zu kommentieren.


Jan
Jan am 18 Sep. 2012
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 am 18 Sep. 2012
Non of answers work !
  1 Kommentar
Jan
Jan am 18 Sep. 2012
Bearbeitet: Jan am 18 Sep. 2012
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"?!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by