How to get mean square error in a quick way using Matlab?

試著忘記壹切 提交于 2019-12-10 19:12:48

问题


I don't know whether this is possible or not but let me explain my question

Imagine that I have the below array

errors=[e1,e2,e3];

Now what I want to calculate is below

MSE=1/(array_lenght)*[e1^2+e2^2+e3^2];

I can make this with a loop but I wonder if there is any quick way.


回答1:


This finds the mean of the squared errors:

MSE = mean(errors.^2)

Each element is squared separately, and then the mean of the resulting vector is found.




回答2:


sum(errors.^2) / numel(errors)



回答3:


Raising powers and adding can be done together instead of sequentially:

MSE = (errors*errors') / numel(errors)


来源:https://stackoverflow.com/questions/13298236/how-to-get-mean-square-error-in-a-quick-way-using-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!