how to subs element of strucs in a loop?

조회 수: 6 (최근 30일)
Amirhosein Ghenaati
Amirhosein Ghenaati 2016년 1월 26일
답변: Walter Roberson 2016년 1월 27일
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
Stephen23
Stephen23 2016년 1월 27일
편집: Stephen23 2016년 1월 27일
Amirhosein Ghenaati's "Answer" moved here:
how can i make a n*n matrix K which has symbolic class and contains all symbolic elements as k11 k12...k1n.I can't obtain K with a for loop
@Amirhosein Ghenaati: please use the comment fields for writing comments.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
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개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by