Search code examples
matlabediting

How can I change the name of the file being saved without editing the code? MatLab


I am working on an experiment that take a lot of data samples and save it to different video files. For example, I take data and save it to a file called "slowmotion.avi" and then I take another set of data and save it to another file called "normalspeed.avi".

I am trying to find a way that I could change the name of file being saved without editing the code. The way I am using right now makes me have to open the code and change the name of the file directory within the code and then save the code. I want to make it a lot faster and easier to use.

I have tried the following code to fix this problem but it doesn't work.

graph=input('Graph of experiment: ');
vidObj = VideoWriter('%3.1f.avi\n',graph);
.....

Hope I didn't confuse you.


Solution

  • A possible solution:

    graph=input('Graph of experiment: ','s');
    vidObj = VideoWriter([graph,'.avi']);
    

    The 's' in the input() function indicates that the expected input is a string, and [graph,'.avi'] simply concatenates both strings.