how to get disp('') to displace in one line instead of many

2 views (last 30 days)
So If I have a function like
e.g.
function v=test(x) v=x+2; disp('The answer is'),disp(v),disp('hooray'); end
, when I put in x=1
I receive the value,
....................................
The answer is
1
hooray
...................................
ans
1
....................................
what do I need to do to get rid of the second part of the answer? (ans 1)
and how do I chance the first part so that the answer become 'The answer is 1 hooray'

Answers (1)

The Matlab Spot
The Matlab Spot on 12 Nov 2013
Edited: The Matlab Spot on 12 Nov 2013
Concat the strings...
function v=test(x)
v=x+2;
disp(['The answer is ',num2str(v),' hooray']);
end
At the command prompt...
>> v=test(1);
The answer is 3 hooray

Tags

Products

Community Treasure Hunt

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

Start Hunting!