Calculating Mean Square Error

Maria (view profile)

on 19 Apr 2014
Latest activity Commented on by Image Analyst

on 28 Feb 2017

Image Analyst (view profile)

What will be the code of the function for calculating Mean Square Error

Image Analyst

Image Analyst (view profile)

on 19 Apr 2014
Is this your homework? Is so, you were supposed to tag it as homework. It really sounds like homework since real world problems are usually not as easy as this.
Christy Lentz

Christy Lentz (view profile)

on 27 Feb 2017
What happens when the returned value is NaN? I'm using 2 arrays of observational measurements and then simulation measurements and trying to find the MSE, but upon using this algorithm I get a NaN back.
Image Analyst

Image Analyst (view profile)

on 28 Feb 2017
What do you want to do when there's a nan. You know there is a 'omitnans' option to mean() don't you?

Image Analyst (view profile)

on 20 Apr 2014

OK so we know the desired signal, at least you could if you made up the equation for it. But what is the actual signal? Do you have that in some array, perhaps that you read in from some kind of position sensor or image analysis? To calculate MSE you need to have two signals - the desired/true signal, and your actual/test signal. Then just do
MSE = mean((desired - mean).^2);

Image Analyst

Image Analyst (view profile)

on 20 Apr 2014
OK, looks like you need a full blown demo. % Demo to plot a point's height as it revolves around a circle.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 22;
xCenter = 12;
yCenter = 10;
% Make a timeline of 40 seconds with samples every 0.01 second.
t = 0 : 0.01 : 40;
% Let's say that there is 8 revolutions in that time.
numberOfRevolutions = 8;
% Produce the angles. They will go from 0 to numberOfRevolutions * 2*pi.
theta = linspace(0, numberOfRevolutions * 2 * pi, length(t));
x = radius * cos(theta) + xCenter;
y = radius * sin(theta) + yCenter;
subplot(1,2,1);
plot(x, y, 'LineWidth', 3);
axis square;
xlim([0 20]);
ylim([0 20]);
grid on;
title('The circlular path it revolves around', 'FontSize', fontSize);
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
% m = -40;
% velocity = 0.25;
% ft = t;
% azimuth = 2 * 3.14 * ft/m;
% Plot azimuth (the y coordinate) as a function of time.
subplot(1,2,2);
plot(t, y, 'b-', 'LineWidth', 3);
grid on;
title('Height of a point as it revolves around', 'FontSize', fontSize);
xlabel('time', 'FontSize', fontSize);
ylabel('Y, or Azimuth', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
Maria

Maria (view profile)

on 21 Apr 2014
Dear Mr Image Analyst many thanks to you , I will try it and feed you back . thanks
Image Analyst

Image Analyst (view profile)

on 9 May 2014
Mick, not sure what your recent edit was, but if I helped you could you mark the answer as "Accepted"? Thanks.