Borrar filtros
Borrar filtros

how to make computations with a cell array?

12 visualizaciones (últimos 30 días)
simo borto
simo borto el 29 de En. de 2015
Editada: Michael Haderlein el 29 de En. de 2015
I have a cell array:
results = {5,2};
that is:
results =
[1x5 double] [1x1 prob.NormalDistribution ]
[1x5 double] [1x1 prob.tLocationScaleDistribution]
[1x5 double] [1x1 gmdistribution ]
[1x5 double] [1x1 gmdistribution ]
[1x5 double] [1x1 struct ]
so there is 5 vectors made of 5 doubles (but the number of vectors is not important). Writing something like:
results{3,1}(2) = 3;
there are no problems: the second place of the third vector of the "first column" of the cell array becomes equal to 3.
My purpose is to compute the minimum value of the fifth places of all the vectors (in the first column of the cell array)
I have tried with:
lower = min(results{:,1}(5));
And it gives:
Bad cell reference operation.
I have tried very different ways to obtain something, but always the same error.
Is there a simple solution to my problem? Thank you in advance

Respuesta aceptada

Guillaume
Guillaume el 29 de En. de 2015
Editada: Guillaume el 29 de En. de 2015
Yes, you can't do that. Mostly because
result{:, 1}
expands into a comma separated list which of course can't be indexed.
If all the vectors of column 1 are the same size, then the simplest thing is to convert that cell column into a matrix, and then operate on a matrix:
col1 = cell2mat(results(:, 1));
lower = min(col1(:, 5))
If the vectors are not the same size, cell2mat won't work and you have to use cellfun to extract this fifth element:
lower = min(cellfun(@(v) v(5), results(:, 1)))

Más respuestas (1)

Michael Haderlein
Michael Haderlein el 29 de En. de 2015
Editada: Michael Haderlein el 29 de En. de 2015
Dear Simo,
min(cellfun(@(x) x(5),results(:,1)))
does the job.
Best regards,
Michael

Categorías

Más información sobre Multidimensional Arrays 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