MATLAB Answers


Return first unique index of values

Asked by Kalai Arasi Mehavarnam on 18 Oct 2018
Latest activity Commented on by Guillaume
on 18 Oct 2018
%function [mu,sig,p] = cifar_10_bayes_learn1(f, trlabel,N)
mu = zeros(10,(N*3));
%sig = zeros(10,3) %task1
sig = zeros((N*3),(N*3),10); %task2
p = zeros(10,1);
for i = 1:10
[row] = (find(label==i));
%[row] = find(trlabel==i-1)
for j=1:N
mu(i,j) = mean(f((row(i,j))));
mu(i,j+N) = mean(f((row(i,j+N))));
mu(i,(j+(2*N))) = mean(f((row(i,(j+(2*N))))));
mu(i,:)=[mu(i,j),mu(i,j+N),mu(i,(j+(2*N)))] %error in this, suscripted assignment dimension mismatch
% sig(:,:,i) = cov(f((row),:))
% %Sig(:,:,i)=(cov(f(row))+cov(f(row),:).')/2;
% p(i) = (length(row) / length(f))
The above code has to return 10 values in row vector,ie, the first index of unique values.The row values should be displayed as 1,2,3,...,10. I wanted to calculate mean,sigma for that particular indexed rows in training data.


Provide the input datas to test
We have no idea what the above code is supposed to do since it's not commented. In addition, it's littered with unnecessary brackets making it harder to read (in my opinion), e.g. the line
mu(i,(j+(2*N))) = mean(f((row(i,(j+(2*N))))));
is simply
mu(i, j+2*N) = mean(f(row(i, j+2*N)));
You should explain the problem you're trying to solve in details, rather than giving us uncommented code that may or may not work.

Sign in to comment.

0 Answers