MATLAB: Change in subs() functionality from 2010b to 2011 a and b

symbolic toolbox

Hi all,
I have code that has worked fine in matlab 2010b using the subs() function for symbolic substitution, however the same code give me an error when running in either the 2011a and b versions. It gives an error indicating mismatching dimension when concatenating somewhere deeper within the subs() function call. The problem arises when the original symbolic expression is a vector or matrix (scalars are fine) and the 'new' and 'old' values are cell arrays (not scalar arguments) of symbolic variables and/or expressions indicating the substitutions needed. I have tested trying to subs into each element of the original vector or matrix expression and that also works, but again can't take in the whole
Doesn't work subs(vector,{old cell}, {new cell})
Does work subs(vector(1), {old cell},{new cell})
Therefore, it seems to be an error in the new edition, although some clarification would be great and an indication if it will be fixed through a patch or something. Otherwise, I would be better of using the old version (though my license expires in 11 days) or write a function to call subs and cycle through each element of the vector or matrix expressions.
The variables in the subs() function call are:
Keq{j}
ans =
[ Keq1 – pSiOg, Keq2 – pCOg, Keq3 – pCO2g]
K>> P(1:sum(glogic))
ans =
[ pSiOg, pCOg, pCO2g]
K>> Pchgvarexp
Pchgvarexp =
[ (R*SiOg*T)/Vpore, (COg*R*T)/Vpore, (CO2g*R*T)/Vpore]
My error messages are: ??? Error using ==> sym.cat>checkDimensions at 76 CAT arguments dimensions are not consistent.
Error in ==> sym.cat>catMany at 39 [resz, ranges] = checkDimensions(sz,dim);
Error in ==> sym.cat at 29 y = catMany(dim, strs);
Error in ==> sym.horzcat at 25 y = cat(2,args{:});
Error in ==> sym.subs>tryFunctionHandle at 213 Y = [Y(:).' usym(:).'];
Error in ==> sym.subs>mupadsubs at 140 [G,worked] = tryFunctionHandle(F,X,Y);
Error in ==> sym.subs at 127 G = mupadsubs(F,X,Y);
Error in ==> ObjectiveFunBuilder_v01 at 91 Keq{j}=subs(Keq{j},P(1:sum(glogic)),Pchgvarexp);
Error in ==> GF_DataB_Cm_v01 at 39 fh = ObjectiveFunBuilder_v01(species,rxinfo,glogic);

Best Answer

HI all,
I wrote a function to get around it, it works for me.
function newfn = subsVECTOR(f,old,new)
% Simple program to get around subs in MATLAB 2011 which for some reason
% they have changed.
nf = size(f,1)
for counter = 1:nf;
newfn(counter,1) = subs(f(counter,1), old, new)
end
best,
craig