Mfj
Mfj

Reputation: 77

How to save a file using a variable in the name?

This is my name now:

  fn_la= ' myfile.env' 

In this name I want to include a variable called date= 20170805. So the name is myfile20170805.env. Some one know how to do that in matlab?

Upvotes: 1

Views: 53

Answers (1)

hello123
hello123

Reputation: 313

Here is the code:

fn_la= ' myfile.env'
date= 20170805
C = strsplit(fn_la,'.')
name=sprintf('%s%d.%s.',C{1},date,C{2})

You might want to use strtrim to remove the whitespace:

name=strtrim(name)

Upvotes: 1

Related Questions