How can I calculate mean and standard deviation of each column in cell arrays with for loop?
조회 수: 5 (최근 30일)
이전 댓글 표시
veri = readtable ('gh.csv');
vericell = table2cell(veri);
ghcolumn = cell2mat(vericell(:,3));
veri.Class = discretize(veri{:, 3}, min(veri{:, 3}):20:max(veri{:, 3})+20);
vericell = table2cell(veri);
class = cell2mat(vericell(:,end));
for ii=1:51
deneme{ii,:}=vericell(class==ii,:);
for j = 1:15
deneme{ii}{:,j};
end
end

I have to calculate the mean and standard deviation of each column of each array with loop. How can I do that?
댓글 수: 0
답변 (1개)
Bob Thompson
2018년 3월 7일
편집: Bob Thompson
2018년 3월 7일
You've really already got your indexing loops set up, you just need the equations.
for ii=1:51 % Loops through each row in deneme array
deneme{ii,:}=vericell(class==ii,:);
for j = 1:15 % Loops through each column of deneme cell contents
meanres = mean(deneme{ii}{:,j});
sdres = deneme{ii}{:,j}-meanres; % I'll admit it's been a while since I've actually calculated standard deviation, so this equation could be wrong, but the proper equation would go here
end
end
If you want to store all of the results, just add extra indexing to meanres and sdres.
댓글 수: 4
Bob Thompson
2018년 3월 7일
편집: Bob Thompson
2018년 3월 7일
If all of deneme{ii} is a series of numbers in individual cells, then you can use cell2mat(deneme{ii}) to convert the interior cells into a regular array, then run mean(deneme{ii}).
Similarly, if deneme{ii}{:,j} are cells that contain just numbers you can still use the cell2mat command.
Basically, the reason you're getting "Too many input arguments" is because it's seeing all of the different cells, rather than the numbers themselves, and mean cannot average a bunch of cell inputs.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!