MATLAB Answers

I have a script file which simply saves some variable into a .txt file format.But now i want that everytime i run the script,it must save .txt file with different name.Please help.

1 view (last 30 days)
Hitesh Kumar
Hitesh Kumar on 18 Nov 2017
Edited: Stephen Cobeldick on 1 Jan 2020
I have a script file which simply saves some variable into a .txt file format.But now i want that everytime i run the script,it must save .txt file with different name.Please help. What i want is when i run script it saves the file as hit.txt, next time when the script is run it must save the file as hit_01.txt, and so on as hit_02.txt, hit_03.txt,etc. everytime when i run the file.

  4 Comments

Show 1 older comment
Stephen Cobeldick
Stephen Cobeldick on 18 Nov 2017
@Hitesh Kumar: both of those pages I linked to have complete working examples. What more do you expect?
If you just looking for someone to write your code for you then you will find plenty of consultants who will be willing to do that for you in return for a few shekels.

Sign in to comment.

Answers (2)

Rik
Rik on 18 Nov 2017
You can use the exist and sprintf functions to do this.

  2 Comments

Rik
Rik on 18 Nov 2017
Look up the documentation.
If you don't want to pay me, you will have to show you actually tried something. I do this for the fun of helping people, not for doing the work for someone else.

Sign in to comment.


Stephen Cobeldick
Stephen Cobeldick on 18 Nov 2017
Edited: Stephen Cobeldick on 1 Jan 2020
You could download my FEX submission nextname. Each time the script runs generate a new filename like this:
name = nextname('hit','_01','.txt')

  0 Comments

Sign in to comment.

Sign in to answer this question.