Change a string by the loop number

조회 수: 1 (최근 30일)
Ismaeel
Ismaeel 2015년 3월 15일
편집: Stephen23 2023년 9월 12일
Hi... How can I change a string with a loop number?
for example,
if we have
x='function#';
for i=1:10
Do something (function1=..., function2=..) and so on
end
I want to change # (the last letter of function#) by the loop number(i=1:10)
I use the function
strrep(x,'#',i)
but it does not wrok
Thanks
  댓글 수: 4
parag patil
parag patil 2018년 5월 1일
But , I do not want to create it intentionally, It is the other software which takes input in the same way of string
Steven Lord
Steven Lord 2018년 5월 1일
parag patil, please clarify how you're calling this "other software" and what it expects its inputs to be.
If it expects text data, perhaps a file name, that you can create using sprintf or num2str. [In the specific case of file names, you can get a list of files in the directory using dir.] If it expects variables that you've created using sequential names, see Stephen's answer for reasons why this is a bad idea.

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

채택된 답변

dpb
dpb 2015년 3월 15일
You can, but don't...see the FAQ for some reasons why not and how to do it "the Matlab way"...
This is in terms of variables but the same holds true for function names as well.
  댓글 수: 1
Ismaeel
Ismaeel 2015년 3월 15일
Very useful information. Thanks dpb... Love MATLAB.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by