sprintf problems
Show older comments
Hello i have a file path which is this '\\psf\Home\Documents\MATLAB\silhouettes\1\00_1' This points to a set of images that i need to add to matlab which works fine. what i need to happen is that when this code is run it changes the one to a two so it would look like this '\\psf\Home\Documents\MATLAB\silhouettes\2\00_1' and then change to three and four etc, i have been told i can use sprintf to do this but cannot see a way to make it work, i don't suppose any out there has any sprintf knowledge who could help me out?
thanks Rob
Accepted Answer
More Answers (1)
Walter Roberson
on 26 Feb 2011
Adjusting Matt's answer slightly to make it more intuitive to program:
for ii = 1:5
S = sprintf('%s%d%s, '\\psf\Home\Documents\MATLAB\silhouettes\', ii, '\00_1')
end
4 Comments
rob wise
on 26 Feb 2011
Matt Fig
on 26 Feb 2011
Walter meant:
S = sprintf('%s%d%s', '\\psf\Home\Documents\MATLAB\silhouettes\', ii, '\00_1')
This is the multi-arg version of the solution!
Matt Fig
on 26 Feb 2011
Speaking of which... It is funny Walter, I learned from you (NG posts) to inline my strings to SPRINTF, rather than passing multiple arguments and one formatter string at the beginning (how I always used to do it)!
Walter Roberson
on 27 Feb 2011
Yeah, but I don't program on Windows with all those \ characters in pathnames. When I start getting strings with numerous \ then I switch styles.
Well, actually if I were programming it myself, I would code inline but use / instead of \\ since Windows will accept / in place of \ .
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!