Borrar filtros
Borrar filtros

Create a list of list and take the mean

3 visualizaciones (últimos 30 días)
Tung
Tung el 18 de Feb. de 2024
Editada: Alexander el 18 de Feb. de 2024
Hi everyone
I am new to Matlab (I came from a Python background).
I have a question about creating a list of arrays and calculating their componentwise means. I know how to this in python using numpy array. I tried to apply the same logic in Matlab but somehow it does not work.
Please find below one example. I want to calculate the componentwise mean of aps. Perhaps, I used the wrong data structure for the aps?
Thank you very much.
aps = {};
for i = 1:length(locs)
aps{i} = [i i+1 i+2];
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 18 de Feb. de 2024
cellfun(@mean, aps) 
  4 comentarios
Voss
Voss el 18 de Feb. de 2024
mean(vertcat(aps{:}),1)
Tung
Tung el 18 de Feb. de 2024
That makes sense. My understanding is that the function cell2mat and vertcat transform the aps into a 2D-array. Once it is done, we can calculate the mean on one of the axes. This is similar to Python. Thank you both!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by