简体   繁体   中英

How to create 3d symbolic tensor?

This works

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

A =

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

But this gives error

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);

How do I create a symbolic 3d tensor in matlab?

A plausible approach is to create a cell array of strings and convert it to symbolic variables:

%// 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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM