You need to supply sprintf with 2 integers, the way you have it written. Instead it should be something simiilar to this:
sprintf('A0000%.2f', str2num(test(1:4)))
Next time, see "help sprintf", "doc sprintf", and/or google "matlab sprintf string to number", etc.
________________________________________
From: SPM (Statistical Parametric Mapping) [[log in to unmask]] on behalf of kambiz rakhshan [[log in to unmask]]
Sent: Sunday, July 08, 2012 10:41 AM
To: [log in to unmask]
Subject: [SPM] question regarding splitting an string in matlab
Dear all,
I am sort of new to matlab and spm and I have a question that I am sure is simple for most of you. I have a string which is named "2.40-resting-s005" and I want to rename it in way that I can compare it with another string using strcmp. However, I need the rename file to be started with letter A following by 4 digits following by dot and finally following with 2 digits like "A0002.40". For doing this I used the following command:
sprintf('A%04d.%d', test)
in which test='2.40-resting-s005'
, but I don't get the output in the format that I want('A0002.40'). Could you please help me to sort out this problem.
Best
Kami
|