Why should I use the zeros function?

조회 수: 25 (최근 30일)
MUNKHBOLOR BAIGALI
MUNKHBOLOR BAIGALI 2020년 10월 22일
편집: Stephen23 2020년 10월 22일
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
Stephen23
Stephen23 2020년 10월 22일
편집: Stephen23 2020년 10월 22일
"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 2020년 10월 22일
I see. Thank you so much

댓글을 달려면 로그인하십시오.

답변 (2개)

Stephan
Stephan 2020년 10월 22일
편집: Stephan 2020년 10월 22일

Durganshu
Durganshu 2020년 10월 22일
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!

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by