better method for evaluating matrix
Afficher commentaires plus anciens
For given vector such as following, I want to make square matrix s such that
%constant, original form
N = 500;
x = 2*pi*linspace(0,1,N);
for i = 1:N
for j = 1:N
s(i,j) = sin(x(i)-x(j))
end
end
But it was too slow, so recently I edited it to following, but it's still too slow!!
Can anybody please help me??
%constant
N = 500;
x = 2*pi*linspace(0,1,N);
for i = 1: N;
s(:,i) = x-x(i);
end
s=sin(s);
Réponse acceptée
Plus de réponses (1)
Andrei Bobrov
le 21 Nov 2017
Modifié(e) : Andrei Bobrov
le 21 Nov 2017
N = 500;
x = 2*pi*linspace(0,1,N);
s = sin(x(:)' - x(:));
for old versions of MATLAB:
s = sin( bsxfun(@minus, x(:)',x(:)) );
1 commentaire
Catégories
En savoir plus sur 시작과 종료 dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!