Effacer les filtres
Effacer les filtres

I got this Error :Matrix dimensions must agree

1 vue (au cours des 30 derniers jours)
Mohammed
Mohammed le 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

Réponses (3)

Andrei Bobrov
Andrei Bobrov le 18 Sep 2012
Modifié(e) : Andrei Bobrov le 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 commentaires
Andrei Bobrov
Andrei Bobrov le 18 Sep 2012
corrected
Jan
Jan le 18 Sep 2012
Mohammed has written [MOVED from answer to comment section]:
But i need 250 variables for t

Connectez-vous pour commenter.


Jan
Jan le 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 le 18 Sep 2012
Non of answers work !
  1 commentaire
Jan
Jan le 18 Sep 2012
Modifié(e) : Jan le 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"?!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by