mean of all positives in a cell array

1 visualización (últimos 30 días)
BoIs
BoIs el 11 de Nov. de 2016
Comentada: Hiskiel Stephanus el 11 de Nov. de 2016
I have a cell array where the cells are something like this: [ 92x1 double] [215x1 double] [127x1 double] [120x1 double] [ 89x1 double] ....and so on(1000 odd cells). I want to find the means of the negative and positive elements in these cells individually. I tried :
if true
% code
end
m = (s{i})<0;
m1 =cellfun(@(x) [mean(mean(x(m,:),2))],s,'un',0)
but when I try the same for all positive elements using n = (s{i})>0; it says index exceeds matrix dimension. Any idea of what I may be doing wrong and how I can fix this or any other suggestions? Thanks!
  1 comentario
Hiskiel Stephanus
Hiskiel Stephanus el 11 de Nov. de 2016
Hi
Please find a solution to your problem in the attached Matlab file. You should of course adjust it accordingly to suit your needs.
Regards Hiskiel

Iniciar sesión para comentar.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 11 de Nov. de 2016
Editada: Andrei Bobrov el 11 de Nov. de 2016
m1 =cellfun(@(x) [mean(x(x<0)),mean(x(x>0))],s,'un',0)
  5 comentarios
BoIs
BoIs el 11 de Nov. de 2016
Thankyou both!! that worked!
BoIs
BoIs el 11 de Nov. de 2016
Im new to matlab, just wanted to know how does the ; at the end exactly help with the error? Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by