Why should I use the zeros function?

34 visualizaciones (últimos 30 días)
MUNKHBOLOR BAIGALI
MUNKHBOLOR BAIGALI el 22 de Oct. de 2020
Editada: Stephen23 el 22 de Oct. de 2020
Hello, I don't understand. Why should I use the zeros function?
Eb=zeros(1,8640);
time1=zeros(1,8640);
diesel=zeros(1,8640);
Edump=zeros(1,8640);
Edch=zeros(1,8640);
Ech=zeros(1,8640);
In this case, I don't understand zeros(1,8640). please explain to me
  2 comentarios
Stephen23
Stephen23 el 22 de Oct. de 2020
Editada: Stephen23 el 22 de Oct. de 2020
"Why should I use the zeros function?"
  1. to avoid bugs by ensuring that a variable has the correct data type (often overlooked in answers).
  2. to improve efficiency by preallocating an array to the required size:
MUNKHBOLOR BAIGALI
MUNKHBOLOR BAIGALI el 22 de Oct. de 2020
I see. Thank you so much

Iniciar sesión para comentar.

Respuestas (2)

Stephan
Stephan el 22 de Oct. de 2020
Editada: Stephan el 22 de Oct. de 2020

Durganshu
Durganshu el 22 de Oct. de 2020
Zeros(m,n) will create a matrix of dimensions m x n with all the elements as 0. This matrix along with the ones(m,n) is often used to pre-allocate a matrix so as to save memory and time of processing.
Read the full documentation here:
Hope that helps!

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by