how to subs element of strucs in a loop?
1 次查看(过去 30 天)
显示 更早的评论
i want to write a program to solve indefinite eqs. answers are located in sol(struct) e.g sol.x1 mean x1 and etc cause number of variable is unknown and they are assigned to symbolic variable(z), I must substitude z with 1 my problem is define a for loop to write following code because I cant define sol.x(i) in a loop
sol=solve(EQ==0)
subs(sol.x1,z,1)
subs(sol.x2,z,1)d
1 个评论
采纳的回答
Walter Roberson
2016-1-27
K = sym('k', n, n)
varnames = fieldnames(sol);
numvars = length(varnames);
solz = struct();
for K = 1 : numvars
thisvar = varnames{K};
solz.(thisvar) = subs(sol.(thisvar), z, 1);
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Construct and Work with Object Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!