1

这有效

A = sym('A%d%d', [2 4])

A =

[ A11, A12, A13, A14]
[ A21, A22, A23, A24]

但这会产生错误

A = sym('A%d%d%d', [2, 4 ,6])
Error using sym>createCharMatrix (line 2001)
Matrix syntax can only create vectors and
matrices.

Error in sym>convertCharWithOption (line 1960)
        s = createCharMatrix(x,a);

Error in sym>tomupad (line 1693)
        S = convertCharWithOption(x,a);

Error in sym (line 113)
            S.s = tomupad(x,a);

如何在 matlab 中创建符号 3d 张量?

4

1 回答 1

3

一种可行的方法是创建一个字符串元胞数组并将其转换为符号变量:

%// Create matrices of indices
[k1 k2 k3] = ndgrid(1:2, 1:4, 1:6);

%// Create a cell array of strings
C = regexp(sprintf('A%d%d%d', [k1(:) k2(:) k3(:)]'), 'A\d{3}', 'match');

%// Convert strings to symbolic objects and convert back into a matrix
A = cell2mat(cellfun(sym, reshape(C, size(k1)), 'UniformOutput', 0));
于 2013-04-02T16:30:46.960 回答