【发布时间】:2012-10-04 09:57:27
【问题描述】:
我正在尝试将四面体中每个面的节点 ID 与其对应的四面体 ID 链接起来。
tetras = [1 2 3 4 % Tetra 1
5 6 7 8] % Tetra 2
对于 tetra 1,有四个面:
faces = [1 2 3; 1 2 4; 1 3 4; 2 3 4] % Notice these are sorted
然后我想将这些存储在数据结构中:
tet_for_face = cell(8,8,8) % 8 allows for the maximum node id
tet_for_face{1,2,3} = 1;
tet_for_face{1,2,4} = 1;
tet_for_face{1,3,4} = 1;
tet_for_face{2,3,4} = 1;
这意味着我可以在 O(1) 中找到任何特定面孔的 tetra ID:
tet_for_face{2,3,3}
ans = []
tet_for_face{2,3,4}
ans = 1
这种方法的问题在于它需要连续的内存。随着我的网格变大,我的内存不足:
cell(1000, 1000, 1000)
??? Error using ==> cell
Out of memory. Type HELP MEMORY for your options.
我也尝试过使用嵌套单元格:
tet = cell(num_nodes, 1);
tet2 = cellfun(@(x) cell(num_nodes, 1), tet, 'UniformOutput', 0);
tet3 = cellfun(@(x) cellfun(@(y) cell(num_nodes, 1), x, 'UniformOutput', 0), tet2, 'UniformOutput', 0);
tet3{2}{3}{4} = 1;
...
虽然这适用于小网格,并且不需要连续内存 (AFAIK),但它有一个令人讨厌的习惯,即在 N=1000 时使 MATLAB 崩溃。
有什么想法吗?
【问题讨论】:
-
你有没有想过使用
sparse数组? -
@HighPerformanceMark 我去看看,干杯!
-
键的字符串/哈希表示如何,并使用
containers.Map?
标签: matlab data-structures tetrahedra