Need help with sprintf formatting

So I have an sprintf statement in a for loop that looks like this:
run='4-QRSVH';
field='by';
files=21;
for f=1:files
fn=sprintf('./data/%s/%s%d.dat', run, field, (f-1)*10000 );
end
In the first loop the value of fn is './data/4-QRSVH/by0.dat' as it should be but then when the loop goes through the next iteration the last part is entirely messed up. It becomes an enormous string and I'm not sure how to fix it. Any suggestions?

댓글 수: 4

Walter Roberson
Walter Roberson 2017년 7월 18일
Could you give an example? The code appears to work for me.
Jesse Randall
Jesse Randall 2017년 7월 18일
Yeah I just tried it in a separate file and it worked. There is a lot more in my code but this is where the issue occurred. I'll look through it more thoroughly and let you know if I find a fix.
Jesse Randall
Jesse Randall 2017년 7월 18일
Ahhhh I found the issue. I added a variable that already existed so it gets overwritten. Thanks for the reply!
Philip Borghesani
Philip Borghesani 2017년 7월 18일
Doing that is usually a good clue that your script (or function) is getting too large and needs to be broken up.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

질문:

2017년 7월 18일

댓글:

2017년 7월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by