Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Samious
Samious le 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'

Réponses (1)

The Matlab Spot
The Matlab Spot le 12 Nov 2013
Modifié(e) : The Matlab Spot le 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

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by