multi-dimensional symbolic arrays
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to create a three-dimensional array of symbolic variables for purposes of formulating and solving an integer programming problem. I need symbolic entries so that I can perform operations using the symbolic toolbox.
I have no problems with a two-dimensional array:
x=sym('x%d%d',[4,4]);
This creates a 4-by-4 symbolic array.
Can this be modified slightly to get an array in three indices?
0 comentarios
Respuestas (2)
Walter Roberson
el 5 de Feb. de 2012
Sorry, no, that syntax is pretty new in MATLAB (R2010b), and only supports vectors or 2 dimensional arrays. For a multi-dimensional work-around, please see http://www.mathworks.com/matlabcentral/answers/2521-creating-vector-of-symbols
0 comentarios
Andrei Bobrov
el 5 de Feb. de 2012
m = 3;
n = 4;
q = 2;
[i1 i2 i3] = ndgrid(1:m,1:n,1:q);
k = cellfun(@sym,regexp(sprintf('x%d_%d_%d',[i1(:) i2(:) i3(:)]'),...
'x[0-9]_[0-9]_[0-9]','match'),'un',0);
x = reshape([k{:}],m,n,[])
OR
m = 3;
n = 4;
q = 2;
[i1 i2 i3] = ndgrid(1:m,1:n,1:q);
k = arrayfun(@(j1)sym(sprintf('x_%d_%d_%d',i1(j1),i2(j1),i3(j1))),...
1:numel(i1),'un',0);
x = reshape([k{:}],m,n,[])
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!