Calculating Mean Square Error

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

3 Commenti

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.
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.
What do you want to do when there's a nan. You know there is a 'omitnans' option to mean() don't you?

Accedi per commentare.

 Risposta accettata

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);

5 Commenti

Maria
Maria il 20 Apr 2014
Dear Image thanks , the actual signal is sensor reading ,regarding equation MSE = mean((desired - mean).^2); I know it . but , the question is how to made it for tracking circular path with 4000 iteration (4000 point in the circle , 40/0.01) ?
This is what you have told me so far:
t = 0 : 0.01 : 40;
m = -40;
velocity = 0.25;
ft = t;
azimuth = 2 * 3.14 * ft/m;
plot(t, azimuth, 'b-');
Now, how do you think you'd get a circle out of that? Your equation for azimuth doesn't look like a circle to me. There's no sin() in there. Have you checked out the FAQ? http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F
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));
radius = 5;
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;
ylim([0, yCenter+radius]);
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 il 21 Apr 2014
Dear Mr Image Analyst many thanks to you , I will try it and feed you back . thanks
Mick, not sure what your recent edit was, but if I helped you could you mark the answer as "Accepted"? Thanks.

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by