Take minimum and maximum of columns in 1x31 cell

223 Views Asked by At

I have a cell array psdMonth that is 1x31, with each cell a 1x114 int 32 in Matlab. I would like to take the minimum of all of the columns of each cell to get a composite minimum that would be 1x114 int 32. So I would want the minimum of psdMonth{1}(1)......psdMonth{31}(1), and then the minimum of psdMonth{1}(2)....pdMonth{31}(2), etc.

I had tried something like this:

 minpsdMonth = min(cat(1,psdMonth{:}))

which does create a 1x114 int32, but I'm not sure how to test if it's actually doing what I think it should. Can anyone tell me how I would get the output I want? Or verify that what I am doing is correct?

Thanks!

2

There are 2 best solutions below

0
On

What you did should be correct. More general approach is to use cellfun:

mi = cellfun(@min,psdMonth);
ma = cellfun(@max,psdMonth);

This would work also when the arrays in each cell are not of the same size.

0
On

I think your approach is correct. Another possibility is

min(cell2mat(psdMonth.'))