Efficiently Averaging Large Sets: Store now, Average later vs. Update now
1 次查看(过去 30 天)
显示 更早的评论
I am wondering if it is more efficient to store large amounts of data and average later or to update the average as data is generated and reduce the storage requirement.
I am looping over the number of samples, S. All vectors and matrices are of unique dimension and are organized in cells. The result of each loop iteration is N new vectors and N new matrices.
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278378/image.png)
Sooner or later, I need to average S column vectors N times, and S Matrices N times.
I see two fundamental approaches to this problem:
1) Create N vectors and N matrices and update them every loop iteration to reflect the average:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278379/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278380/image.png)
So there would be
storage requirements and
of these calculations.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278381/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278382/image.png)
2) Store
vectors and
matrices, and then call the MatLab function mean()
times to recover the averages.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278383/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278384/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278385/image.png)
So there would be
storage requirements and the mean() function would be called
times.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278386/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278387/image.png)
My gut tells me
calculations is a losing proposition, but I wonder if someone with more expertise than me could comment? Thank you!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278388/image.png)
2 个评论
Aghamarsh Varanasi
2020-3-24
Choosing one of the approach that you have mentioned should totally depend on your design and other constraints. For example, If you wanted to develop the algorithm for a system with memory limitations, then you could use the first approach. If you wanted less computation, you can use the second approach.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!