How can I write a loop, which can make the parameter "V" change with a cyclic variable "i"?

조회 수: 1 (최근 30일)
My code is:
netlist = ['D:\1\MATLAB\mine.txt'];
code =['D:\\1\\MATLAB\\mine.asc\r\n'...
'R1 N001 0 {R}\r\n'...
'C1 N001 0 {C}\r\n'...
'V1 N001 0 {V}\r\n'...
'.tran .1\r\n'...
'.params R = 1000 C = 0.001 V = 15\r\n'...
'.backanno\r\n'...
'.end\r\n'];
fid = fopen(netlist,'w+');
fprintf(fid,code);
fid = fclose(fid);
I have to make the parameter "V" change with a cyclic variable "i". Is there any way to do that?
  댓글 수: 1
Ujjwal Pratik
Ujjwal Pratik 2020년 4월 17일
Hi Zhenyu ,
I am facing a similar issue.
Can you share your code to show how you used "strcat" and "num2str" within a loop.?

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

채택된 답변

Vladimir Sovkov
Vladimir Sovkov 2020년 1월 29일
Use Matlab functions "strcat" and "num2str" within a loop.
  댓글 수: 3
Ujjwal Pratik
Ujjwal Pratik 2020년 4월 17일
I am facing a similar issue.
Can you share your code to show how you used "strcat" and "num2str" within a loop.?
Zhenyu Wu
Zhenyu Wu 2020년 4월 18일
Of course. Here is my code.
netlist = ['D:\1\MATLAB\mine.net'];
code1 =['D:\\1\\MATLAB\\mine.asc\r\n'...
'R1 N001 0 {R}\r\n'...
'C1 N001 0 {C}\r\n'...
'V1 N001 0 SINE(0 {ampl} {freq})\r\n'...
'.tran .1\r\n'];
code2 =['.params R = 1000 C = 0.001 V = 15\r\n'];
code3 =['.backanno\r\n'...
'.end\r\n'];
for i=1:10
v=15*i;
vv=num2str(v);
code2=strcat('.params R = 1000 C = 0.001 V = ',vv);
fid = fopen(netlist,'w+');
fprintf(fid,code1);
fprintf(fid,code2);
fprintf(fid,code3);
fid = fclose(fid);
end;

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by