My cell array has 861 rows and each row has vectors of varying sizes. I want to calculate std dev only for cells that have 20 elements. Others should give a value of 0. How do I tell cellfun to get only the cells with 20 elements. Here is my attempt
2 views (last 30 days)
Show older comments
Syeda Amberin
on 22 May 2018
Commented: Syeda Amberin
on 22 May 2018
Stds=cellfun(@std ,ratios,'UniformOutput',false); % trying to calculate standard dev for cells for cell array 'ratios' that have 20 elements. All other cells should give 0.
0 Comments
Accepted Answer
the cyclist
on 22 May 2018
Edited: the cyclist
on 22 May 2018
ratios = {rand(19,1); rand(20,1); rand(21,1)}
cellfun(@(x)std(x)*(numel(x)==20),ratios)
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices 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!