How do I efficiently find the mean and covariance of a cell containing matrices with different rows?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Chak Chan
el 10 de Oct. de 2018
Editada: ANKUR KUMAR
el 10 de Oct. de 2018
I have a 1x15 cell which contains 15 matrices, and each of them has different number of rows but all have the same number of columns(14). I am trying to find the mean and covariance of the whole cell. I compute them by concatenating all matrices into a big matrix and use the built-in functions to get the result, which looks like this:
M = C{1};
for i=2:15
M = [M; C{i}];
end
mean = mean(M);
cov = cov(M);
I think this approach does not fully take advantage of the flexibility of cells. Is there a more efficient way to do that?
0 comentarios
Respuesta aceptada
ANKUR KUMAR
el 10 de Oct. de 2018
Editada: ANKUR KUMAR
el 10 de Oct. de 2018
Use concatenate to mix up all cells into one matrix.
cat(2,C{:}); %you can use this only if number of rows must be same in all cells
or
cat(1,C{:}); %for your data
After using cat, calculate mean and cov in usual manner.
As your data have the different number of rows in all cells, you cannot use cat(2,C{:}).
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings 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!