cell2mat too slow
11 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
更多回答(1 个)
Yazan
2021-7-29
To speed up the computations, you simply need to avoid using structure arrays.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!