Professional Documents
Culture Documents
MATLABText
Subject: Central Home
and variable in oneMy Newsreader
Reply to Page Post A New Message
this message What isSearch
Advanced a Watch
line Add author to My Watch List List?
From:
Help Ben View original format
Date: 23 Mar, 2009 20:40:20 Flag as spam
Tags for this
Message: 1 of 8
Thread
How do you display both a text and a numerical value for a variable in just one line, text,
one line. For example, here are my variable string, hi,
there is a small t...
x = 2;
Add a New Tag:
How do i display the result as
1 of 6 4/23/2017 7:14 PM
MATLAB Central - Text and variable in one line https://www.mathworks.com/matlabcentral/newsreader/view_thread/2...
>
> How do i display the result as
>
> The value of x is 2.
MATLAB Central Home My Newsreader Page Post A New Message Advanced Search
>
> I tried
Help
> disp('The value of x is'); disp(x);
>
> but the numerical value is not in line with the text.
> Thanks
Hi,
disp([The value of x is ' num2str(x)])
Joe
2 of 6 4/23/2017 7:14 PM
MATLAB Central - Text and variable in one line https://www.mathworks.com/matlabcentral/newsreader/view_thread/2...
"Joe Sababa"
MATLAB wrote in message
Central Home <gq8tll$g69$1@fred.mathworks.com>...
My Newsreader Page Post A New Message Advanced Search
> "Ben " <benlawr2000@yahoo.com> wrote in message
<gq8s3k$n21$1@fred.mathworks.com>...
Help
> > How do you display both a text and a numerical value for a variable in
just one line. For example, here are my variable
>>
> > x = 2;
>>
> > How do i display the result as
>>
> > The value of x is 2.
>>
> > I tried
> > disp('The value of x is'); disp(x);
>>
> > but the numerical value is not in line with the text.
> > Thanks
> Hi,
> disp([The value of x is ' num2str(x)])
>
> Joe
3 of 6 4/23/2017 7:14 PM
MATLAB Central - Text and variable in one line https://www.mathworks.com/matlabcentral/newsreader/view_thread/2...
> Hi,
> disp([The value of x is ' num2str(x)])
>
> Joe
MATLAB Central Home My Newsreader Page Post A New Message Advanced Search
Hi,
A small typo though:
Help
disp(['The value of x is ', num2str(x)])
> Hi,
> A small typo though:
>
> disp(['The value of x is ', num2str(x)])
>
4 of 6 4/23/2017 7:14 PM
MATLAB Central - Text and variable in one line https://www.mathworks.com/matlabcentral/newsreader/view_thread/2...
>
> The value of x is 3.141593
:)
>> x=[1:3].'*pi;
>> num2str(x,'The value of x is %f')
ans =
The value of x is 3.141593
The value of x is 6.283185
The value of x is 9.424778
>> whos ans
Name Size Bytes Class Attributes
ans 3x26 156 char
>>
While the second case superficially _looks_ the same on the screen,
that's only because of the embedded \n; it's still just one long string
in actuality.
5 of 6 4/23/2017 7:14 PM
MATLAB Central - Text and variable in one line https://www.mathworks.com/matlabcentral/newsreader/view_thread/2...
--
MATLAB Central Home My Newsreader Page Post A New Message Advanced Search
Feed for this Thread
Help
6 of 6 4/23/2017 7:14 PM