How to use the several average of same class

조회 수: 2 (최근 30일)
Kong
Kong 2020년 4월 5일
편집: Kong 2020년 4월 6일
Hello.
I have a data (90 x 2857), column 2857 is a label(class).
I want to select 5 rows of the same classes randomly and compute the mean of each 5 rows.
(10 Combination 5)
So I want to get all possible combinations' average values of the same classes.
In this code, I computed all rows of the same class and got one average value.
Could you explain how to fix the code?
data = csvread('outfile.csv');
values = data(:,1:end-1);
labels = data(:,end);
avg = splitapply(@(x) {mean(x,1)}, values, labels+1);

채택된 답변

David Hill
David Hill 2020년 4월 5일
a=randi(size(values,1),5,1);%randomly choose 5 rows
avg=mean(values(a,:),2);%compute mean of the rows
  댓글 수: 5
David Hill
David Hill 2020년 4월 5일
b=randperm(length(avg),5);
for k=1:5
a(k)=mean(avg{b(k)});
end
Kong
Kong 2020년 4월 5일
Thank you so much. I got this error.
data = csvread('outfile.csv');
values = data(:,1:end-1);
labels = data(:,end);
avg = splitapply(@(x) {mean(x,1)}, values, labels+1);
a=mean(avg{randi(length(values),1)});
b=randperm(length(avg),5 );
for k=1:5
a(k)=mean(avg{b(k)});
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by