Using loop instead of arrayfun in matlab

浪子不回头ぞ 提交于 2019-12-12 03:38:01

问题


I have created 3d Cell array "mycell" of size 1x100x19.

val(:,:,1) = 

Columns 1 through 3

{3x1 cell}    {3x1 cell}    {3x1 cell}

Columns 4 through 6

{3x1 cell}    {3x1 cell}    {3x1 cell}

Columns 7 through 13

[]    []    []    []    []    []    [].....


val(:,:,2) = 

Columns 1 through 7

[]    []    []    []    []    []    []

Columns 8 through 13

{3x1 cell}    []    []    []    []    []......

and so on till mycell(:,:,19).

As I cannot delete empty rows or colums, I concatenate using arrayfun like this:

mycell = arrayfun(@(x)cat(2, mycell{:,:,x}), 1:size(mycell, 3), 'uni', 0);

It gives me result like this:

Columns 1 through 3

{3x6 cell}    {3x1 cell}    {3x73 cell} ....

The result is okay but it is slow.Is there any way that I can do this with loop instead of arrayfun, because I check for loop is faster than arrayfun.

Any help will be appreciated.

来源:https://stackoverflow.com/questions/36749648/using-loop-instead-of-arrayfun-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!