Thread Subject: sprintf format

Subject: sprintf format

From: Lanyi Xu

Date: 30 Sep, 2008 18:43:03

Message: 1 of 3

Dear all,

After many years using Matlab, I lost both my C language skill and books. The problem is simple. However, I don't know how to do it.

I'd like to print out time in standard time format, suppose
hh=1;
mm=3;
ss=25;
str1=sprintf('%2d:%2d:%2d',hh,mm,ss);
text(1,0,str1);

it gives me
1: 3:25
However, I would like it to be
01:03:25

How could I do it?

Thanks a lot in advance

Lanyi

Subject: sprintf format

From: Miroslav Balda

Date: 30 Sep, 2008 18:50:19

Message: 2 of 3

"Lanyi Xu" <lanyixu@yahoo.ca> wrote in message <gbtrvm$ror$1@fred.mathworks.com>...
> Dear all,
>
> After many years using Matlab, I lost both my C language skill and books. The problem is simple. However, I don't know how to do it.
>
> I'd like to print out time in standard time format, suppose
> hh=1;
> mm=3;
> ss=25;
> str1=sprintf('%2d:%2d:%2d',hh,mm,ss);
> text(1,0,str1);
>
> it gives me
> 1: 3:25
> However, I would like it to be
> 01:03:25
>
> How could I do it?
>
> Thanks a lot in advance
>
> Lanyi
>

Hi,
Try
str1=sprintf('%02d:%02d:%02d',hh,mm,ss);
Mira

Subject: sprintf format

From: Lanyi Xu

Date: 30 Sep, 2008 19:00:02

Message: 3 of 3

"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <gbtsdb$3e0$1@fred.mathworks.com>...
> "Lanyi Xu" <lanyixu@yahoo.ca> wrote in message <gbtrvm$ror$1@fred.mathworks.com>...
> > Dear all,
> >
> > After many years using Matlab, I lost both my C language skill and books. The problem is simple. However, I don't know how to do it.
> >
> > I'd like to print out time in standard time format, suppose
> > hh=1;
> > mm=3;
> > ss=25;
> > str1=sprintf('%2d:%2d:%2d',hh,mm,ss);
> > text(1,0,str1);
> >
> > it gives me
> > 1: 3:25
> > However, I would like it to be
> > 01:03:25
> >
> > How could I do it?
> >
> > Thanks a lot in advance
> >
> > Lanyi
> >
>
> Hi,
> Try
> str1=sprintf('%02d:%02d:%02d',hh,mm,ss);
> Mira

Thanks a lot, Mira. It works.

Cheer

Lanyi

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com