Put a matrix back to zeros (looking for an elegant solution)
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Walter Roberson
2012-12-26
A(:) = 0;
9 个评论
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
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
2012-12-26
That's what I would do. zeros is the most elegant want to create zeros :)
2 个评论
Sean de Wolski
2012-12-26
You could write clean() to do this if you wanted, considerably less elegant though...
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!