Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
Samious
Samious am 12 Nov. 2013
Bearbeitet: The Matlab Spot am 12 Nov. 2013
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'

Antworten (1)

The Matlab Spot
The Matlab Spot am 12 Nov. 2013
Bearbeitet: The Matlab Spot am 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

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by