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:
sprintf

Subject: sprintf

From: Hans

Date: 18 Jan, 2010 07:02:04

Message: 1 of 10

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 10

"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 10

"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 10

"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 10

"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 10

"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

Subject: sprintf

From: Steven Lord

Date: 19 Jan, 2010 15:19:51

Message: 7 of 10


"Hans " <jyde_6@msn.com> wrote in message
news:hj3jqp$8e7$1@fred.mathworks.com...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
> <hj1eif$chl$1@fred.mathworks.com>...

*snip*

> 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?

Uicontrols do not have an Interpreter property and so cannot interpret TeX
commands.

Text objects do have an Interpreter property and so can interpret TeX in
their String property.

http://www.mathworks.com/access/helpdesk/help/techdoc/infotool/hgprop/text_frame.html

But note that text objects can't be children of a figure window (like
uicontrols can), but must be a child of an axes, hggroup, or hgtransform
object as documented in the description of the Parent property.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: sprintf

From: Yair Altman

Date: 19 Jan, 2010 17:34:25

Message: 8 of 10

"Steven Lord" <slord@mathworks.com> wrote in message <hj4iij$2bm$1@fred.mathworks.com>...
>
> "Hans " <jyde_6@msn.com> wrote in message
> news:hj3jqp$8e7$1@fred.mathworks.com...
> > "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
> > <hj1eif$chl$1@fred.mathworks.com>...
>
> *snip*
>
> > 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?
>
> Uicontrols do not have an Interpreter property and so cannot interpret TeX
> commands.
>
> Text objects do have an Interpreter property and so can interpret TeX in
> their String property.
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/infotool/hgprop/text_frame.html
>
> But note that text objects can't be children of a figure window (like
> uicontrols can), but must be a child of an axes, hggroup, or hgtransform
> object as documented in the description of the Parent property.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


I am not exactly sure what the OP meant:

1. You can create an axes and use the \alpha Tex notation in the text() function. The axes background and borders can be made transparent, which enables displaying Tex labels anywhere in your figure (but beneath uicontrols).
2. Alternately, you can use a Matlab button uicontrol, and set the alpha symbol using HTML (alpha = &# 945;), as explained here: http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/
3. Alternately, you can use a Java JLabel control, and set the alpha symbol using HTML, as explained here: http://undocumentedmatlab.com/blog/customizing-matlab-labels/
4. Alternately, you can display the alpha symbol within an HTML-based edit-pane, as explained here: http://undocumentedmatlab.com/blog/gui-integrated-html-panel/

There are several other variants, but these should be sufficient for most use-cases.

Yair Altman
http://UndocumentedMatlab.com

Subject: sprintf

From: Hans

Date: 20 Jan, 2010 06:58:06

Message: 9 of 10

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hj4qf1$9c7$1@fred.mathworks.com>...
> "Steven Lord" <slord@mathworks.com> wrote in message <hj4iij$2bm$1@fred.mathworks.com>...
> >
> > "Hans " <jyde_6@msn.com> wrote in message
> > news:hj3jqp$8e7$1@fred.mathworks.com...
> > > "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
> > > <hj1eif$chl$1@fred.mathworks.com>...
> >
> > *snip*
> >
> > > 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?
> >
> > Uicontrols do not have an Interpreter property and so cannot interpret TeX
> > commands.
> >
> > Text objects do have an Interpreter property and so can interpret TeX in
> > their String property.
> >
> > http://www.mathworks.com/access/helpdesk/help/techdoc/infotool/hgprop/text_frame.html
> >
> > But note that text objects can't be children of a figure window (like
> > uicontrols can), but must be a child of an axes, hggroup, or hgtransform
> > object as documented in the description of the Parent property.
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>
>
> I am not exactly sure what the OP meant:
>
> 1. You can create an axes and use the \alpha Tex notation in the text() function. The axes background and borders can be made transparent, which enables displaying Tex labels anywhere in your figure (but beneath uicontrols).
> 2. Alternately, you can use a Matlab button uicontrol, and set the alpha symbol using HTML (alpha = &# 945;), as explained here: http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/
> 3. Alternately, you can use a Java JLabel control, and set the alpha symbol using HTML, as explained here: http://undocumentedmatlab.com/blog/customizing-matlab-labels/
> 4. Alternately, you can display the alpha symbol within an HTML-based edit-pane, as explained here: http://undocumentedmatlab.com/blog/gui-integrated-html-panel/
>
> There are several other variants, but these should be sufficient for most use-cases.
>
> Yair Altman
> http://UndocumentedMatlab.com

Dear Yair and Steve

Thank you for taking time to help me. As I understand uicontrol cannot show symbols. In my example I have a GUI with a list box where different options can be choosed. The options are then shown in a textbox when I press the pushbutton. Can you come up with an example how to solve my problem soo symbols can be shown in the textbox?Yair can you show me two examples with option 1 and 2 that you mentioned or maybe one of the others? I do not have experience with Java programming. Hope the example under can shown what I want.

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');

uicontrol('style','pushbutton',...
    'units','normalized',...
    'position',[0.325 0.1 0.10 0.04],...
    'string','Table',...
    'backgroundcolor',col,...
    'callback',@go99709);
 
 


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);

 hlb576=uicontrol('style','listbox',...
    'units','normalized',...
    'position',[0.3 0.3 0.15 0.1],...
    'string',{'y11';'y22'});
    
    function go99709(varargin)

    choice=get(hlb576,'value');
    if choice==1
    y6=[10 20 30 40]
    y66=[1 2 3 4]
    set(ht2,'string',sprintf('%.0f \\circ %.0f min\n',[y6';y66']))
    elseif choice==2
    set(ht2,'string','Car price')
    end
    end
end

Best Regards

Hans

Subject: sprintf

From: Hans

Date: 20 Jan, 2010 15:57:05

Message: 10 of 10

"Hans " <jyde_6@msn.com> wrote in message <hj69hu$1rn$1@fred.mathworks.com>...
> "Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hj4qf1$9c7$1@fred.mathworks.com>...
> > "Steven Lord" <slord@mathworks.com> wrote in message <hj4iij$2bm$1@fred.mathworks.com>...
> > >
> > > "Hans " <jyde_6@msn.com> wrote in message
> > > news:hj3jqp$8e7$1@fred.mathworks.com...
> > > > "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
> > > > <hj1eif$chl$1@fred.mathworks.com>...
> > >
> > > *snip*
> > >
> > > > 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?
> > >
> > > Uicontrols do not have an Interpreter property and so cannot interpret TeX
> > > commands.
> > >
> > > Text objects do have an Interpreter property and so can interpret TeX in
> > > their String property.
> > >
> > > http://www.mathworks.com/access/helpdesk/help/techdoc/infotool/hgprop/text_frame.html
> > >
> > > But note that text objects can't be children of a figure window (like
> > > uicontrols can), but must be a child of an axes, hggroup, or hgtransform
> > > object as documented in the description of the Parent property.
> > >
> > > --
> > > Steve Lord
> > > slord@mathworks.com
> > > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> >
> >
> > I am not exactly sure what the OP meant:
> >
> > 1. You can create an axes and use the \alpha Tex notation in the text() function. The axes background and borders can be made transparent, which enables displaying Tex labels anywhere in your figure (but beneath uicontrols).
> > 2. Alternately, you can use a Matlab button uicontrol, and set the alpha symbol using HTML (alpha = &# 945;), as explained here: http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/
> > 3. Alternately, you can use a Java JLabel control, and set the alpha symbol using HTML, as explained here: http://undocumentedmatlab.com/blog/customizing-matlab-labels/
> > 4. Alternately, you can display the alpha symbol within an HTML-based edit-pane, as explained here: http://undocumentedmatlab.com/blog/gui-integrated-html-panel/
> >
> > There are several other variants, but these should be sufficient for most use-cases.
> >
> > Yair Altman
> > http://UndocumentedMatlab.com
>
> Dear Yair and Steve
>
> Thank you for taking time to help me. As I understand uicontrol cannot show symbols. In my example I have a GUI with a list box where different options can be choosed. The options are then shown in a textbox when I press the pushbutton. Can you come up with an example how to solve my problem soo symbols can be shown in the textbox?Yair can you show me two examples with option 1 and 2 that you mentioned or maybe one of the others? I do not have experience with Java programming. Hope the example under can shown what I want.
>
> 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');
>
> uicontrol('style','pushbutton',...
> 'units','normalized',...
> 'position',[0.325 0.1 0.10 0.04],...
> 'string','Table',...
> 'backgroundcolor',col,...
> 'callback',@go99709);
>
>
>
>
> 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);
>
> hlb576=uicontrol('style','listbox',...
> 'units','normalized',...
> 'position',[0.3 0.3 0.15 0.1],...
> 'string',{'y11';'y22'});
>
> function go99709(varargin)
>
> choice=get(hlb576,'value');
> if choice==1
> y6=[10 20 30 40]
> y66=[1 2 3 4]
> set(ht2,'string',sprintf('%.0f \\circ %.0f min\n',[y6';y66']))
> elseif choice==2
> set(ht2,'string','Car price')
> end
> end
> end
>
> Best Regards
>
> Hans

Anybody that can help me?
I would really appreciate if anybody could come up with a modified edition of the example I have shown above.

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