Put a matrix back to zeros (looking for an elegant solution)

조회 수: 1 (최근 30일)
André Pacheco
André Pacheco 2012년 12월 26일
Hello,
I have one matrix that is generated withe zeros:
A=zeros(5,4);
And, during the cycle matrix A get different values to make some math. I want that in the end of the cycle the matrix A come back to is original values so it can start it all over. Is there any elegant solution or should i just use the same code that used to initialize the matrix?

채택된 답변

Walter Roberson
Walter Roberson 2012년 12월 26일
  댓글 수: 9
Walter Roberson
Walter Roberson 2012년 12월 27일
Now that I have turned off the processes using 7.1 of my 8 CPUs, I get much more reproducible results. Times still overlap, but in my test, A(:)=0 tends to be lower, and A=A-A; tends to be lower still. Maximum variability between all the possibilities was 0.305 (A-A) to 0.319 (zeros(2000,2000)). Not even close to 50%. (This for a simplified version without the rand())
Walter Roberson
Walter Roberson 2012년 12월 27일
R2012a on MacBook Pro, OS-X Lion, i7 CPUs, the A(:)=0 consistently tests slightly faster when I use Sean's code, not slower at all.
Sean, did you forget to turn off your disk defragger while you were testing? :)

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

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 12월 26일
That's what I would do. zeros is the most elegant want to create zeros :)
  댓글 수: 2
André Pacheco
André Pacheco 2012년 12월 26일
I thought there was something like A=clean; And it would clean the matrix :D Something like harry potter style :D
Sean de Wolski
Sean de Wolski 2012년 12월 26일
You could write clean() to do this if you wanted, considerably less elegant though...

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

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by