Insert a string into code

조회 수: 2 (최근 30일)
ly
ly 2015년 10월 20일
댓글: ly 2015년 10월 20일
I want to insert a string in to code:
...
name='time';
filename = 'name_v1.txt';
...
Can the 'time' be inserted in " name_v1.txt"?

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 10월 20일
ly - if the idea is to replace the 'name' substring within 'name_v1.txt' with 'time', then you could use strrep to accomplish this. For example,
filename = 'name_v1.txt';
filename = strrep(filename,'name','time');
would set filename to
filename =
time_v1.txt
Or, you could use sprintf to do something similar
name = 'time';
filename = sprintf('%s_v1.txt',name);
which would (agains) set filename to 'time_v1.txt'.
  댓글 수: 1
ly
ly 2015년 10월 20일
This is what I need:
Or, you could use sprintf to do something similar
name = 'time';
filename = sprintf('%s_v1.txt',name);
which would (agains) set filename to 'time_v1.txt'.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by