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

New to MATLAB?

Thread Subject:
sprintf

Subject: sprintf

From: Hans

Date: 18 Jan, 2010 07:02:04

Message: 1 of 6

Hello everybody


How can I get sprintf to a write a string in latex?

Example:

y_1=[1 2 3 4]
sprintf('%.0f \alpha\n', y_1)

It must be a string output

Best Regards

Hans

Subject: sprintf

From: kinor

Date: 18 Jan, 2010 07:41:03

Message: 2 of 6

"Hans " <jyde_6@msn.com> wrote in message <hj111c$ego$1@fred.mathworks.com>...
> Hello everybody
>
>
> How can I get sprintf to a write a string in latex?
>
> Example:
>
> y_1=[1 2 3 4]
> sprintf('%.0f \alpha\n', y_1)
>
> It must be a string output
>
> Best Regards
>
> Hans

Hi Hans,

hope

sprintf('%.0f \\alpha\n', y_1)

does it

kinor

Subject: sprintf

From: Bruno Luong

Date: 18 Jan, 2010 07:44:03

Message: 3 of 6

"Hans " <jyde_6@msn.com> wrote in message <hj111c$ego$1@fred.mathworks.com>...
> Hello everybody
>
>
> How can I get sprintf to a write a string in latex?
>
> Example:
>
> y_1=[1 2 3 4]
> sprintf('%.0f \alpha\n', y_1)
>

Replace \ with \\

Bruno

Subject: sprintf

From: Hans

Date: 18 Jan, 2010 10:04:03

Message: 4 of 6

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hj13g3$k23$1@fred.mathworks.com>...
> "Hans " <jyde_6@msn.com> wrote in message <hj111c$ego$1@fred.mathworks.com>...
> > Hello everybody
> >
> >
> > How can I get sprintf to a write a string in latex?
> >
> > Example:
> >
> > y_1=[1 2 3 4]
> > sprintf('%.0f \alpha\n', y_1)
> >
>
> Replace \ with \\
>
> Bruno

Hi Bruno and kinor

If I try:

y_1=[1 2 3 4]
sprintf('%.0f \\alpha\n', y_1)

I get :
>> sprintf('%.0f \\alpha\n', y_1)

ans =

1 \alpha
2 \alpha
3 \alpha
4 \alpha

I want it to show the alpha in symbol?

Best Regards

Hans

Subject: sprintf

From: Bruno Luong

Date: 18 Jan, 2010 10:53:03

Message: 5 of 6

"Hans " <jyde_6@msn.com> wrote in message <hj1bmj$9an$1@fred.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hj13g3$k23$1@fred.mathworks.com>...
> > "Hans " <jyde_6@msn.com> wrote in message <hj111c$ego$1@fred.mathworks.com>...
> > > Hello everybody
> > >
> > >
> > > How can I get sprintf to a write a string in latex?
> > >
> > > Example:
> > >
> > > y_1=[1 2 3 4]
> > > sprintf('%.0f \alpha\n', y_1)
> > >
> >
> > Replace \ with \\
> >
> > Bruno
>
> Hi Bruno and kinor
>
> If I try:
>
> y_1=[1 2 3 4]
> sprintf('%.0f \\alpha\n', y_1)
>
> I get :
> >> sprintf('%.0f \\alpha\n', y_1)
>
> ans =
>
> 1 \alpha
> 2 \alpha
> 3 \alpha
> 4 \alpha
>
> I want it to show the alpha in symbol?

You confuse, sprintf format the simple *string* (char array), the TeX/LaTex interpretation come later, when the string is used in graphic command such as XLABEL, TITLE...

Bruno

Subject: sprintf

From: Hans

Date: 19 Jan, 2010 06:35:05

Message: 6 of 6

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hj1eif$chl$1@fred.mathworks.com>...
> "Hans " <jyde_6@msn.com> wrote in message <hj1bmj$9an$1@fred.mathworks.com>...
> > "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hj13g3$k23$1@fred.mathworks.com>...
> > > "Hans " <jyde_6@msn.com> wrote in message <hj111c$ego$1@fred.mathworks.com>...
> > > > Hello everybody
> > > >
> > > >
> > > > How can I get sprintf to a write a string in latex?
> > > >
> > > > Example:
> > > >
> > > > y_1=[1 2 3 4]
> > > > sprintf('%.0f \alpha\n', y_1)
> > > >
> > >
> > > Replace \ with \\
> > >
> > > Bruno
> >
> > Hi Bruno and kinor
> >
> > If I try:
> >
> > y_1=[1 2 3 4]
> > sprintf('%.0f \\alpha\n', y_1)
> >
> > I get :
> > >> sprintf('%.0f \\alpha\n', y_1)
> >
> > ans =
> >
> > 1 \alpha
> > 2 \alpha
> > 3 \alpha
> > 4 \alpha
> >
> > I want it to show the alpha in symbol?
>
> You confuse, sprintf format the simple *string* (char array), the TeX/LaTex interpretation come later, when the string is used in graphic command such as XLABEL, TITLE...
>
> Bruno

Dear Bruno and Kinor

Thank very much for taking time to help me. Sorry for confusing you. I will try to explain my problem again. I have a gui and I want to make a string that is output in a text window. I can not get it to show the alpha symbol?
My original GUI is more complicated where I have some listboxes where I can choose different data series that are imported and shown in the text window.

Example:

function test6()


global vectorOfValues
vectorOfValues = [];

f=figure('name','test',...
    'numbertitle','off',...
    'menubar','none',...
    'color',[0.85, 0.85, 0.85],...
    'units','normalized',...
    'position',[0 0.1 0.95 0.87]);

col=get(f,'color');


ht2=uicontrol('style','text',...
    'units','normalized',...
    'position',[0.5, 0.3,0.4 0.5],...
    'backgroundcolor',[0.95, 0.95, 0.95],...
    'string','',...
    'fontsize',15);

 y=[10 20 30 40]
 set(ht2,'string',sprintf('%.0f \\alpha\n',y))


end



Hope the example illustrate my problem with showing symbols in text window by using string input from set function.

Best Regards

Hans

Tags for 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