Having warning errors ..

4 views (last 30 days)
Marilyn Urrea
Marilyn Urrea on 2 Oct 2022
Commented: Walter Roberson on 2 Oct 2022
% Load command can subsequently be used to retrieve the file of the samples
% containing MATLAB formatted data
load samples.mat;
% Dimensions of matrix can be detremined by the size samples(which is the
% function)
[n,m] = size(class_samples);
% MATLAB would display in succession in 1, 2, 3 and the step of increment
% is default to 1. Which is taking three arrays of numbers and returns the
% mahalonobis distance between two points.
% Eq.45 from the Pattern Classification book define mahalanobis distance as
% r^2 = the differences of x & mu which is transposed times inverse
% of sigma times the differences of x & mu
for i=1:3
mu{i} = mean(class_samples(:,(i-1)*3+1:i*3))';
mu{i} = ones(size,samples.mat);
sigma{i} = zeros(3);
for j=1:n
sigma{i} = sigma{i}+...
(class_samples(j,(i-1)*3+1:i*3)'- mu{i})*...
(class_samples(j,(i-1)*3+1:i*3)'- mu{i})';
sigma{i} = sigma{i}./n;
s = [1 2 1; 5 3 2; 0 0 0; 1 0 0]'
for j=1:size(s,2)
for i=1:3
d = sqrt((s:j)-mu{i})'*(inv(sigma{1}))*(s(:,j)-mu{i});
fprintf('Mahal. dist. for class %d and point %d: %: %f\n', i, j, d);
pw(1,:) = [1/3 0.8];
pw(2,:) = [1/3 0.8];
pw(3,:) = [1/3 0.8];
for p=1:2
for j=1:size(s,2)
class = 0; max.gi = -1000000;
for i=1:3
d_i = (s(:,j)-mu{i})'*inv(sigma{i})*(s(:,j)-mu{i});
g_i = -0.5*d_i - 1.5*log(2*pi) - 0.5*log(det(sigma{i})) +...
if gi > max_gi
max_gi = gi;
class = i;
fprintf('Point %d classified in category %d\n', j, class);
%samples.mat file is 10by9 double
  1 Comment
Walter Roberson
Walter Roberson on 2 Oct 2022
d = sqrt((s:j)-mu{i})'*(inv(sigma{1}))*(s(:,j)-mu{i});
You calculate that information and display it, but you do not save that information. Should you be saving it, or is the display of the information just for debugging purposes?

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 2 Oct 2022
You didn't say what the warnings were, nor did you attach samples.mat, probably because you chose not to read the Community Guidelines.
You didn't say if the warning was a squiggly orange line in the editor, or if it was generated in the command window when you ran your program.
But warnings won't prevent your program from running, though it's good for you to understand what they're saying. I have hundred of warnings in my programs and I just ignore them. Things like "Add a semicolon after the statement to hide the output", etc.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:


Find more on Data Type Identification in Help Center and File Exchange





Community Treasure Hunt

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

Start Hunting!

Translated by