How vectorize this operation
Afficher commentaires plus anciens
Can someone help me please?
x = 10*ones((10^7),1);
L = ((length(x)*2):-2:2)';
M = x.*L;
p= -M./L;
c= 0.25;
x = x+c*p;
Is possible vectorize x = x+c*p;
5 commentaires
Iori Yagami Kusanagi
le 8 Oct 2018
Bruno Luong
le 8 Oct 2018
Modifié(e) : Bruno Luong
le 8 Oct 2018
Are you awared that you creates arrays of few hundred of Tb?
Iori Yagami Kusanagi
le 8 Oct 2018
Bruno Luong
le 9 Oct 2018
Modifié(e) : Bruno Luong
le 9 Oct 2018
You know how much memory has your PC? Usually few or few dozen Gb. How you intend to carry out the storage of such matrix on the computer?
Réponses (1)
Jan
le 9 Oct 2018
The code works vectorized already. So the problem is not vectorizing.
The code can be simplified slightly:
M = x .* L;
p = -x; % instead of: -M ./ L, but p is not needed at all
c = 0.25;
x = (1-c) * x; % instead of: x + c * p;
The code is not meaningful yet. Maybe there is another way to improve it. But again, vectorization is applied here already.
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!