Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Creating filename with both text and variables

Subject: Creating filename with both text and variables

From: Chris Klich

Date: 12 Nov, 2010 14:49:03

Message: 1 of 3

This is a very simple question, but I am fairly new to Matlab, and I can't seem to get a filename created that both includes my own "quoted" text, as well as variables/strings.

I want to create a filename that looks like:

../wrfout_d01_2005-09-0', a, '_', t, ':00:00.nc' where a and t are single digit numbers. I have converted these numbers to strings using num2str, but it still does not seem to work. I would like the final file name to look something like:

../wrfout_d01_2005-09-01_20:00:00.nc

Thank you!

Subject: Creating filename with both text and variables

From: ImageAnalyst

Date: 12 Nov, 2010 14:54:14

Message: 2 of 3

Use sprintf(). It's pretty easy. Just like in C, if you're familiar
with that language. Even if you're not, it's easy to figure out.

Subject: Creating filename with both text and variables

From: Sean

Date: 12 Nov, 2010 14:59:04

Message: 3 of 3

"Chris Klich" <JerzeyDevil521@aol.com> wrote in message <ibjk4v$a8c$1@fred.mathworks.com>...
> This is a very simple question, but I am fairly new to Matlab, and I can't seem to get a filename created that both includes my own "quoted" text, as well as variables/strings.
>
> I want to create a filename that looks like:
>
> ../wrfout_d01_2005-09-0', a, '_', t, ':00:00.nc' where a and t are single digit numbers. I have converted these numbers to strings using num2str, but it still does not seem to work. I would like the final file name to look something like:
>
> ../wrfout_d01_2005-09-01_20:00:00.nc
>
> Thank you!

['../wrfout_d01_2005-0' num2str(a) '_' num2str(t) ':00:00.nc']

The look at the different string formatting options to get the number in the format you want.
doc num2str

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us