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:
Text and variable in one line

Subject: Text and variable in one line

From: Ben

Date: 23 Mar, 2009 20:40:20

Message: 1 of 3

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

Subject: Text and variable in one line

From: Matt Fig

Date: 23 Mar, 2009 20:59:02

Message: 2 of 3

fprintf('The value of x is %i.\n',x)

Subject: Text and variable in one line

From: Joe Sababa

Date: 23 Mar, 2009 21:07:01

Message: 3 of 3

"Ben " <benlawr2000@yahoo.com> wrote in message <gq8s3k$n21$1@fred.mathworks.com>...
> 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

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