小编Mat*_*tal的帖子

混合类型的Matlab数据结构 - 什么时间+空间效率?

我需要处理大量混合类型的表格数据 - 字符串和双精度数据.我想是一个标准问题.Matlab中用于处理此问题的最佳数据结构是什么?

Cellarray肯定不是答案.它的内存效率极低.(测试如下所示).数据集(来自统计工具箱)的时间和空间非常低效.这留下了structarray或数组结构.我在下面对时间和内存的所有四个不同选项进行了测试,在我看来,数组的结构是我测试的东西的最佳选择.

我对Matlab相对较新,坦率地说这有点令人失望.无论如何 - 寻找关于我是否遗漏某些东西,或者我的测试是否准确/合理的建议.除了访问/转换/内存使用之外,我还缺少其他注意事项,因为我使用这些东西编写代码更多.(我正在使用R2010b)

**测试#1:访问速度访问数据项.

cellarray:0.002s
dataset:36.665s       %<<< This is horrible
structarray:0.001s
struct of array:0.000s
Run Code Online (Sandbox Code Playgroud)

**测试#2:转换速度和内存使用情况我从此测试中删除了数据集.

Cellarray(doubles)->matrix:d->m: 0.865s
Cellarray(mixed)->structarray:c->sc: 0.268s
Cellarray(doubles)->structarray:d->sd: 0.430s
Cellarray(mixed)->struct of arrays:c->sac: 0.361s
Cellarray(doubles)->struct of arrays:d->sad: 0.887s
  Name           Size               Bytes  Class     Attributes
    c         100000x10            68000000  cell                
    d         100000x10            68000000  cell                
    m         100000x10             8000000  double              
    sac            1x1             38001240  struct              
    sad            1x1              8001240  struct              
    sc        100000x1             68000640  struct              
    sd        100000x1             68000640  struct  
Run Code Online (Sandbox Code Playgroud)

==================代码:测试#1

  %% cellarray
  c = cell(100000,10);
  c(:,[1,3,5,7,9]) = num2cell(zeros(100000,5));
  c(:,[2,4,6,8,10]) …
Run Code Online (Sandbox Code Playgroud)

performance matlab large-data bigdata data-structures

6
推荐指数
1
解决办法
2945
查看次数