How can I calculate mean and standard deviation of each column in cell arrays with for loop?

1 view (last 30 days)
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?

Answers (1)

Bob Thompson
Bob Thompson on 7 Mar 2018
Edited: Bob Thompson on 7 Mar 2018
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 Comments
Bob Thompson
Bob Thompson on 7 Mar 2018
Edited: Bob Thompson on 7 Mar 2018
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.

Sign in to comment.

Categories

Find more on Programming 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!