How can I just display a sentence with words and values in my function using only a string and without the values showing again?

1 view (last 30 days)
function A = Area_of_a_circle()
r = input('Enter radius: ');
A = 2*pi*r^2;
s = ['The area of a circle with radius ',num2str(r),' is ', num2str(A)'.'];
disp(s)
end
  5 Comments
TADA
TADA on 1 Nov 2018
I don't get this issue over here.
maybe you didn't put a semicolon ; after calling Area_of_a_circle?
A = Area_of_a_circle()
gives this output:
The area of a circle with radius 10 is 628.3185.
A =
628.3185
but if you add a semicolon
A = Area_of_a_circle();
you get the output you wanted
Also, like walter mentioned you need a comma or space after the num2str to get the last period like that matlab transposes A twice instead of concatenating the period

Sign in to comment.

Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!