how to use multiple '%c' on each variable ?
5 ビュー (過去 30 日間)
古いコメントを表示
Hello, im trying to write text to some files in array.
Here is my code :
clear
clc
VariantModel = compose('%c', 'A':'E')
VariantFy = compose('%c', [235000,335000,435000,535000,635000])
for k = 1:numel(VariantModel)
writefile(VariantModel{k})
end
files = dir('*.s2k');
files(:).name
function writefile(C)
fido = fopen("Model"+C+".s2k",'wt');
newline = '\n\n'
spacing = '\n'
%here variable "VariantModel" works
line1='File D:\\MAGISTER\\KULIAH\\TESIS\\Model%c.s2k was saved on m/d/yy at h:mm:ss'
line2='TABLE: "PROGRAM CONTROL"'
line3=' ProgramName=SAP2000 Version=25.0.0 ProgLevel=Ultimate LicenseNum=3010*1D6KZBK478DMQCT LicenseOS=Yes LicenseSC=Yes LicenseHT=No CurrUnits="KN, m, C" SteelCode="AISC 360-10" ConcCode="ACI 318-19" AlumCode="AA 2015" _'
line4=' ColdCode=AISI-16 RegenHinge=Yes'
line5='TABLE: "ACTIVE DEGREES OF FREEDOM"'
line6=' UX=Yes UY=No UZ=Yes RX=No RY=Yes RZ=No'
line7='TABLE: "ANALYSIS OPTIONS"'
line8=' Solver=Advanced SolverProc=Auto Force32Bit=No StiffCase=None GeomMod=None HingeOpt="In Elements" NumAThreads=0 MaxFileSize=0 NumDThreads=0 NumRThreads=0 UseMMFiles="Program Determined" AllowDiff=No'
line9='TABLE: "COORDINATE SYSTEMS"'
line10=' Name=GLOBAL Type=Cartesian X=0 Y=0 Z=0 AboutZ=0 AboutY=0 AboutX=0'
line11='TABLE: "GRID LINES"'
line12=' CoordSys=GLOBAL AxisDir=X GridID=A XRYZCoord=-6 LineType=Primary LineColor=Gray8Dark Visible=Yes BubbleLoc=End AllVisible=Yes BubbleSize=1,5'
line13=' CoordSys=GLOBAL AxisDir=X GridID=B XRYZCoord=0 LineType=Primary LineColor=Gray8Dark Visible=Yes BubbleLoc=End'
line14=' CoordSys=GLOBAL AxisDir=X GridID=C XRYZCoord=6 LineType=Primary LineColor=Gray8Dark Visible=Yes BubbleLoc=End'
line15=' CoordSys=GLOBAL AxisDir=Y GridID=1 XRYZCoord=0 LineType=Primary LineColor=Gray8Dark Visible=Yes BubbleLoc=Start'
line16=' CoordSys=GLOBAL AxisDir=Z GridID=Z1 XRYZCoord=0 LineType=Primary LineColor=Gray8Dark Visible=Yes BubbleLoc=End'
line17=' CoordSys=GLOBAL AxisDir=Z GridID=Z2 XRYZCoord=3 LineType=Primary LineColor=Gray8Dark Visible=Yes BubbleLoc=End'
line18=' CoordSys=GLOBAL AxisDir=Z GridID=Z3 XRYZCoord=6 LineType=Primary LineColor=Gray8Dark Visible=Yes BubbleLoc=End'
line19='TABLE: "MATERIAL PROPERTIES 01 - GENERAL"'
line20=' Material=4000Psi Type=Concrete Grade="' + "f'c 4000 " + 'psi"'+ ' SymType=Isotropic TempDepend=No Color=Green GUID=b0920fc0-a39b-46e4-a096-037f0f0739a7 Notes="Customary '+"f'c 4000 psi "+'01/02/2024 20:13:33"'
line21=' Material=A416Gr270 Type=Tendon Grade="Grade 270" SymType=Uniaxial TempDepend=No Color=Cyan GUID=d02be965-452b-41cb-8cdb-2b3b29b19d11 Notes="ASTM A416 Grade 270 01/02/2024 20:40:51"'
line22=' Material=BJ-37 Type=Steel Grade="Grade 50" SymType=Isotropic TempDepend=No Color=Magenta Notes="ASTM A992 Grade 50 01/02/2024 20:03:34"'
line23='TABLE: "MATERIAL PROPERTIES 02 - BASIC MECHANICAL PROPERTIES"'
line24=' Material=4000Psi UnitWeight=23,5631216161854 UnitMass=2,40276960558926 E1=24855578,0600518 G12=10356490,8583549 U12=0,2 A1=9,89999952793124E-06'
line25=' Material=A416Gr270 UnitWeight=76,9728639422648 UnitMass=7,84904737995992 E1=196500599,8512 A1=1,16999994421006E-05'
line26=' Material=BJ-37 UnitWeight=76,9728639422648 UnitMass=7,84904737995992 E1=199947978,795958 G12=76903068,7676762 U12=0,3 A1=1,16999994421006E-05'
line27='TABLE: "MATERIAL PROPERTIES 03A - STEEL DATA"'
%here variable "VariantFy" works
line28=' Material=BJ-37 Fy=235000 Fu=352500 EffFy=235000 EffFu=352500 SSCurveOpt=Simple SSHysType=Kinematic SHard=0,015 SMax=0,11 SRup=0,17 FinalSlope=-0,1 CoupModType="Von Mises"'
line29='TABLE: "MATERIAL PROPERTIES 06 - DAMPING PARAMETERS"'
line30=' Material=4000Psi ModalRatio=0 VisMass=0 VisStiff=0 HysMass=0 HysStiff=0'
line31=' Material=A416Gr270 ModalRatio=0 VisMass=0 VisStiff=0 HysMass=0 HysStiff=0'
line32=' Material=BJ-37 ModalRatio=0 VisMass=0 VisStiff=0 HysMass=0 HysStiff=0'
line33='TABLE: "MATERIAL PROPERTIES 09 - ACCEPTANCE CRITERIA"'
line34=' Material=4000Psi IOTens=0,01 LSTens=0,02 CPTens=0,05 IOComp=-0,003 LSComp=-0,006 CPComp=-0,015 IgnoreTens=Yes'
line35=' Material=A416Gr270 IOTens=0,015 LSTens=0,023 CPTens=0,03 IOComp=-0,015 LSComp=-0,023 CPComp=-0,03'
line36=' Material=BJ-37 IOTens=0,01 LSTens=0,02 CPTens=0,05 IOComp=-0,005 LSComp=-0,01 CPComp=-0,02'
line37='TABLE: "FRAME SECTION PROPERTIES 01 - GENERAL"'
line38=' SectionName=BigWF Material=BJ-37 Shape="I/Wide Flange" t3=0,75 t2=0,5 tf=0,05 tw=0,04 t2b=0,5 tfb=0,05 FilletRadius=0 Area=0,076 TorsConst=5,23707333333334E-05 I33=0,00705083333333333 I22=0,00104513333333333 _'
line39=' I23=0 AS2=0,03 AS3=0,0416666666666667 S33Top=0,0188022222222222 S33Bot=0,0188022222222222 S22Left=0,00418053333333333 S22Right=0,00418053333333333 Z33=0,021725 Z22=0,00651 R33=0,304588448249466 _'
line40=' R22=0,117267874483871 CGOffset3=0 CGOffset2=0 EccV2=0 EccV3=0 Cw=0,000127604166666667 ConcCol=No ConcBeam=No Color=Blue TotalWt=0 TotalMass=0 FromFile=No AMod=1 A2Mod=1 A3Mod=1 JMod=1 I2Mod=1 _'
line41=' I3Mod=1 MMod=1 WMod=1'
combine1 = append(line1,newline,line2,spacing,line3,spacing,line4,newline,line5,spacing,line6,newline,line7,spacing,line8,newline,line9,spacing,line10,newline,line11,spacing,line12,spacing,line13,spacing,line14,spacing,line15,spacing,line16,spacing,line17,spacing,line18,newline,line19,spacing,line20,spacing,line21,spacing,line22,newline,line23,spacing,line24,spacing,line25,spacing,line26,newline,line27,spacing,line28,newline,line29,spacing,line30,spacing,line31,spacing,line32,newline,line33,spacing,line34,spacing,line35,spacing,line36)
combine2 = append(combine1,newline,line37,spacing,line38,spacing,line39,spacing,line40,spacing,line41)
fprintf(fido,combine2,C);
fclose(fido);
end
Basicaly, I want the result as i descripted below :
File ModelA.s2k :
at line1 will be = 'File D:\\MAGISTER\\KULIAH\\TESIS\\ModelA.s2k was saved on m/d/yy at h:mm:ss'
at line28 will be = ' Material=BJ-37 Fy=235000 Fu=352500 etc.'
File ModelB.s2k :
at line1 will be = 'File D:\\MAGISTER\\KULIAH\\TESIS\\ModelB.s2k was saved on m/d/yy at h:mm:ss'
at line28 will be = ' Material=BJ-37 Fy=335000 Fu=352500 etc.'
etc.
thank you.
1 件のコメント
Mario Malic
2024 年 3 月 25 日
Please generate a document with your input file. Read it into a cell or string array, and edit the array and generate an input file with edited array.
採用された回答
Star Strider
2024 年 3 月 25 日
Add ‘VariantFy’ as an argument to the function as ‘L28’ (or whatever you choose to call it):
function writefile(C,L28)
and change ‘Line28’ to:
line28=sprintf(' Material=BJ-37 Fy=%6d Fu=%6d EffFy=%6d EffFu=%6d SSCurveOpt=Simple SSHysType=Kinematic SHard=0,015 SMax=0,11 SRup=0,17 FinalSlope=-0,1 CoupModType="Von Mises"',str2double(L28)*ones(1,4))
and call the function as:
writefile(VariantModel{k},VariantFy{k});
and it works!
Als, put semicolons (;) at the ends of the lines in the function to keep them from printing out to the Command Window every time you clal the function.
clear
clc
VariantModel = compose('%c', 'A':'E')
VariantFy = compose('%c', [235000,335000,435000,535000,635000])
for k = 1:numel(VariantModel)
writefile(VariantModel{k},VariantFy{k});
end
files = dir('*.s2k');
files(:).name
type(files(end).name) % Look At The Last File
function writefile(C,L28)
fido = fopen("Model"+C+".s2k",'wt');
newline = '\n\n'
spacing = '\n'
%here variable "VariantModel" works
line1='File D:\\MAGISTER\\KULIAH\\TESIS\\Model%c.s2k was saved on m/d/yy at h:mm:ss'
line2='TABLE: "PROGRAM CONTROL"'
line3=' ProgramName=SAP2000 Version=25.0.0 ProgLevel=Ultimate LicenseNum=3010*1D6KZBK478DMQCT LicenseOS=Yes LicenseSC=Yes LicenseHT=No CurrUnits="KN, m, C" SteelCode="AISC 360-10" ConcCode="ACI 318-19" AlumCode="AA 2015" _'
line4=' ColdCode=AISI-16 RegenHinge=Yes'
line5='TABLE: "ACTIVE DEGREES OF FREEDOM"'
line6=' UX=Yes UY=No UZ=Yes RX=No RY=Yes RZ=No'
line7='TABLE: "ANALYSIS OPTIONS"'
line8=' Solver=Advanced SolverProc=Auto Force32Bit=No StiffCase=None GeomMod=None HingeOpt="In Elements" NumAThreads=0 MaxFileSize=0 NumDThreads=0 NumRThreads=0 UseMMFiles="Program Determined" AllowDiff=No'
line9='TABLE: "COORDINATE SYSTEMS"'
line10=' Name=GLOBAL Type=Cartesian X=0 Y=0 Z=0 AboutZ=0 AboutY=0 AboutX=0'
line11='TABLE: "GRID LINES"'
line12=' CoordSys=GLOBAL AxisDir=X GridID=A XRYZCoord=-6 LineType=Primary LineColor=Gray8Dark Visible=Yes BubbleLoc=End AllVisible=Yes BubbleSize=1,5'
line13=' CoordSys=GLOBAL AxisDir=X GridID=B XRYZCoord=0 LineType=Primary LineColor=Gray8Dark Visible=Yes BubbleLoc=End'
line14=' CoordSys=GLOBAL AxisDir=X GridID=C XRYZCoord=6 LineType=Primary LineColor=Gray8Dark Visible=Yes BubbleLoc=End'
line15=' CoordSys=GLOBAL AxisDir=Y GridID=1 XRYZCoord=0 LineType=Primary LineColor=Gray8Dark Visible=Yes BubbleLoc=Start'
line16=' CoordSys=GLOBAL AxisDir=Z GridID=Z1 XRYZCoord=0 LineType=Primary LineColor=Gray8Dark Visible=Yes BubbleLoc=End'
line17=' CoordSys=GLOBAL AxisDir=Z GridID=Z2 XRYZCoord=3 LineType=Primary LineColor=Gray8Dark Visible=Yes BubbleLoc=End'
line18=' CoordSys=GLOBAL AxisDir=Z GridID=Z3 XRYZCoord=6 LineType=Primary LineColor=Gray8Dark Visible=Yes BubbleLoc=End'
line19='TABLE: "MATERIAL PROPERTIES 01 - GENERAL"'
line20=' Material=4000Psi Type=Concrete Grade="' + "f'c 4000 " + 'psi"'+ ' SymType=Isotropic TempDepend=No Color=Green GUID=b0920fc0-a39b-46e4-a096-037f0f0739a7 Notes="Customary '+"f'c 4000 psi "+'01/02/2024 20:13:33"'
line21=' Material=A416Gr270 Type=Tendon Grade="Grade 270" SymType=Uniaxial TempDepend=No Color=Cyan GUID=d02be965-452b-41cb-8cdb-2b3b29b19d11 Notes="ASTM A416 Grade 270 01/02/2024 20:40:51"'
line22=' Material=BJ-37 Type=Steel Grade="Grade 50" SymType=Isotropic TempDepend=No Color=Magenta Notes="ASTM A992 Grade 50 01/02/2024 20:03:34"'
line23='TABLE: "MATERIAL PROPERTIES 02 - BASIC MECHANICAL PROPERTIES"'
line24=' Material=4000Psi UnitWeight=23,5631216161854 UnitMass=2,40276960558926 E1=24855578,0600518 G12=10356490,8583549 U12=0,2 A1=9,89999952793124E-06'
line25=' Material=A416Gr270 UnitWeight=76,9728639422648 UnitMass=7,84904737995992 E1=196500599,8512 A1=1,16999994421006E-05'
line26=' Material=BJ-37 UnitWeight=76,9728639422648 UnitMass=7,84904737995992 E1=199947978,795958 G12=76903068,7676762 U12=0,3 A1=1,16999994421006E-05'
line27='TABLE: "MATERIAL PROPERTIES 03A - STEEL DATA"'
%here variable "VariantFy" works
line28=sprintf(' Material=BJ-37 Fy=%6d Fu=%6d EffFy=%6d EffFu=%6d SSCurveOpt=Simple SSHysType=Kinematic SHard=0,015 SMax=0,11 SRup=0,17 FinalSlope=-0,1 CoupModType="Von Mises"',str2double(L28)*ones(1,4))
line29='TABLE: "MATERIAL PROPERTIES 06 - DAMPING PARAMETERS"'
line30=' Material=4000Psi ModalRatio=0 VisMass=0 VisStiff=0 HysMass=0 HysStiff=0'
line31=' Material=A416Gr270 ModalRatio=0 VisMass=0 VisStiff=0 HysMass=0 HysStiff=0'
line32=' Material=BJ-37 ModalRatio=0 VisMass=0 VisStiff=0 HysMass=0 HysStiff=0'
line33='TABLE: "MATERIAL PROPERTIES 09 - ACCEPTANCE CRITERIA"'
line34=' Material=4000Psi IOTens=0,01 LSTens=0,02 CPTens=0,05 IOComp=-0,003 LSComp=-0,006 CPComp=-0,015 IgnoreTens=Yes'
line35=' Material=A416Gr270 IOTens=0,015 LSTens=0,023 CPTens=0,03 IOComp=-0,015 LSComp=-0,023 CPComp=-0,03'
line36=' Material=BJ-37 IOTens=0,01 LSTens=0,02 CPTens=0,05 IOComp=-0,005 LSComp=-0,01 CPComp=-0,02'
line37='TABLE: "FRAME SECTION PROPERTIES 01 - GENERAL"'
line38=' SectionName=BigWF Material=BJ-37 Shape="I/Wide Flange" t3=0,75 t2=0,5 tf=0,05 tw=0,04 t2b=0,5 tfb=0,05 FilletRadius=0 Area=0,076 TorsConst=5,23707333333334E-05 I33=0,00705083333333333 I22=0,00104513333333333 _'
line39=' I23=0 AS2=0,03 AS3=0,0416666666666667 S33Top=0,0188022222222222 S33Bot=0,0188022222222222 S22Left=0,00418053333333333 S22Right=0,00418053333333333 Z33=0,021725 Z22=0,00651 R33=0,304588448249466 _'
line40=' R22=0,117267874483871 CGOffset3=0 CGOffset2=0 EccV2=0 EccV3=0 Cw=0,000127604166666667 ConcCol=No ConcBeam=No Color=Blue TotalWt=0 TotalMass=0 FromFile=No AMod=1 A2Mod=1 A3Mod=1 JMod=1 I2Mod=1 _'
line41=' I3Mod=1 MMod=1 WMod=1'
combine1 = append(line1,newline,line2,spacing,line3,spacing,line4,newline,line5,spacing,line6,newline,line7,spacing,line8,newline,line9,spacing,line10,newline,line11,spacing,line12,spacing,line13,spacing,line14,spacing,line15,spacing,line16,spacing,line17,spacing,line18,newline,line19,spacing,line20,spacing,line21,spacing,line22,newline,line23,spacing,line24,spacing,line25,spacing,line26,newline,line27,spacing,line28,newline,line29,spacing,line30,spacing,line31,spacing,line32,newline,line33,spacing,line34,spacing,line35,spacing,line36)
combine2 = append(combine1,newline,line37,spacing,line38,spacing,line39,spacing,line40,spacing,line41)
fprintf(fido,combine2,C);
fclose(fido);
end
.
6 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Aerospace Applications についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!