Mean Value in a variables cell array

Hello everyone,
I am looking for the following problems already almost desperate. The problem is as follows. I have a Cell Array which is structured as follows (see picture) 40 rows x 100 columns. The distance between the data points (each datapoint is a vector with 284 elements) is always 9 fields. However, the starting point varies. I need the mean value for each row (40 mean values in total). Between the single vector values, which I need for the determination of the mean values, there are empty rows ([ ]). Thus, I expect a cell array with 40 rows, each containing 284 values ( mean of the data points (vectors) )
I have already tried any variations (expand with NaN, loops, etc.). With cell2mat I do not get further. Does anyone have an idea ?

 Respuesta aceptada

Stephen23
Stephen23 el 16 de Mayo de 2021
Where C is your cell array:
N = size(C,1);
M = nan(N,1);
for k = 1:N
M(k) = mean([C{k,:}]);
end

5 comentarios

Leonard Haensel
Leonard Haensel el 16 de Mayo de 2021
Hello Mr. Cobeldick,
thank you very much for your answer. Unfortunately I get the error message " Unable to perform assignment because the left and right sides have a
different number of elements." Probably my formulation of the problem was not precise enough. Each datapoint consists of a vector with 284 elements.
Stephen23
Stephen23 el 16 de Mayo de 2021
Editada: Stephen23 el 16 de Mayo de 2021
"Probably my formulation of the problem was not precise enough."
Correct.
Assuming that you intend to take the mean of all values in one row of the cell array and that all non-empty cells contain a column vector:
N = size(C,1);
M = nan(N,1);
for k = 1:N
M(k) = mean(vertcat(C{k,:}));
end
Leonard Haensel
Leonard Haensel el 16 de Mayo de 2021
I apologize for the imprecise wording. This is my first forum entry. I want to average all vectors in each row of the Cell array. Thus, I expect a cell array with 40 rows, each containing 284 values ( mean of the data points (vectors) ). The 40 rows represent one measurement series. Thus I would like to get a mean value of the data points for each measurement series.
N = size(C,1);
D = cell(N,1);
for k = 1:N
D{k} = mean([C{k,:}],2);
end
Leonard Haensel
Leonard Haensel el 17 de Mayo de 2021
I would like to thank you very much. You have helped me a lot. I will try to formulate my next forum entry precisely enough from the beginning.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Versión

R2020b

Preguntada:

el 16 de Mayo de 2021

Comentada:

el 17 de Mayo de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by