Creating input file but replacing variables

조회 수: 1 (최근 30일)
Konstantinos Belivanis
Konstantinos Belivanis 2015년 3월 1일
답변: Ganesh Gaonkar 2015년 3월 31일
Hello all,
I want to create input files in Matlab. All I need to do is to change some variables. As a result I want to change only some portions of the text or values and run them through loops. A portion of what I want is the following:
mdb.models[' Modelname- i '].sketches['__profile__'].rectangle(point1=(0.0, t_cover +( N -1)*( t_steel + t_int )+ t_steel ),
point2=( L , 2* t_cover +(N-1)*( t_steel + t_int )+ t_steel ))
So want the text above to be stacked i times and all the variables above (in bold) to be substituted with variables already defined (string for the Modelname variable and numeric values for the others).
Last step would be to save the created text into a .py file.
Thank you so much!

채택된 답변

Ganesh Gaonkar
Ganesh Gaonkar 2015년 3월 31일
In general , when you have requirements which has combination of some texts with some variables which changes every i'th time, One of the way to get it done is by using 'eval' function inside your loop .You can find more details on this function here

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by