cell2mat too slow

11 visualizaciones (últimos 30 días)
Douglas Chiang
Douglas Chiang el 29 de Jul. de 2021
Comentada: Douglas Chiang el 31 de Jul. de 2021
Hi community,
I am trying to extract all poses from a struct by:
arrayfun(@(node)(node.pose), nodes, 'UniformOutput', false)
It gives me something like this:
ans =
50×1 cell array
{[ -0.2232 6.2129 0.8631 -0.5050 0]}
{[-0.5066 5.4770 -0.9729 -0.2310 0]}
{[ -0.2650 6.0300 0.7742 -0.6329 0]}
{[ -0.0436 5.4497 0.7313 -0.6820 0]}
{[ -0.0892 5.5517 -0.4583 0.8888 0]}
{[ 0.4760 6.0669 -0.3153 -0.9490 0]}
{[ -0.5377 6.2957 0.9279 -0.3729 0]}
{[-0.6971 5.9071 -0.7730 -0.6344 0]}
...
But I want it to be a matrix like this:
ans =
-0.2232 6.2129 0.8631 -0.5050 0
-0.5066 5.4770 -0.9729 -0.2310 0
-0.2650 6.0300 0.7742 -0.6329 0
-0.0436 5.4497 0.7313 -0.6820 0
-0.0892 5.5517 -0.4583 0.8888 0
0.4760 6.0669 -0.3153 -0.9490 0
-0.5377 6.2957 0.9279 -0.3729 0
-0.6971 5.9071 -0.7730 -0.6344 0
...
So I use cell2mat:
cell2mat(arrayfun(@(node)(node.pose), nodes, 'UniformOutput', false))
But the function cell2mat is spending around 50% of runtime for my program, which slow down quite a lot.
Is there anyway to avoid cell2mat that has an efficient runtime?
Thanks

Respuesta aceptada

Bruno Luong
Bruno Luong el 29 de Jul. de 2021
Try
cat(1, nodes.pose)

Más respuestas (1)

Yazan
Yazan el 29 de Jul. de 2021
To speed up the computations, you simply need to avoid using structure arrays.

Categorías

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

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by