Hi,
(I had some code which was running fine in Matlab 2014a but after upgrading to 2015a today, the same code is not working)
I want to create a symbolic variable t and it's value to contain further symbolic variables called as t1, t2, t3 and so on, wherein the number of these symbolic variable to be determined by a user provided value stored under "NumOfExpVar"
I wrote the below code and it works perfectly in Matlab 2014a and also in 2015a.
NumOfExpVar = 1; % This value will be set by user
t = sym(zeros(1, NumOfExpVar));for NEVCnter=1:NumOfExpVar t(NEVCnter) = sym(sprintf('t%d', NEVCnter));end
So far so good.
Now, after a long series of intermediate code (which has nothing to do with "t" symbolic variables) I have another code wherein for each of t1, t2 etc I want to create symbolic variables x1_1, x1_2, x1_3…(stored under t1), x2_1, x2_2, x2_3 etc (stored under t2) wherein the number after "_" is determined by "ExpRunCnter". The code I have is
ExpRunCnter = 2; %This value is set dynamically depending on state of the program
for NEVCnter = 1:NumOfExpVar t(NEVCnter) = sym(zeros(1, ExpRunCnter)); for ERCCnter = 1:ExpRunCnter t(NEVCnter,ERCCnter) = sym(sprintf('x%d_%d', NEVCnter, ERCCnter)); end end
Unfortunately the above does NOT work in 2015a (but did work in 2014a)
Please let know.
Thanks
Hari
PS: the error I get in 2015a is as follows (error pointing to the line "t(NEVCnter) = sym(zeros(1, ExpRunCnter));":
Error using subsasgn In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in sym/privsubsasgn (line 997) L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn (line 834) C = privsubsasgn(L,R,inds{:});
Best Answer