0

I have a data set with n samples d features represented by a n*d matrix. The corresponding label is a n*1 vector. How can I compute each intraclass standard deviation without loops in matlab?

For example:

Samples

 5     1     1     1     4
 5     2     5     3     1
 1     3     5     5     5
 5     5     3     4     5
 4     5     5     5     4

Label:

2
1
1
2
2

How can I compute class 1 and class 2's standard deviation?

liu
  • 937
  • 1
  • 9
  • 15

1 Answers1

4

Using accumarray, you can calculate the standard deviations like this:

stdev = cell2mat(accumarray(label,(1:length(label))',[],@(x){std(samples(x,:))}));

If you have the Statistics toolbox, you can use grpstats instead:

stdev = grpstats(samples,label,'std')
Jonas
  • 74,690
  • 10
  • 137
  • 177