Beginner question: how to display a comment for answers

2 vues (au cours des 30 derniers jours)
Sam
Sam le 13 Juil 2014
Modifié(e) : Jan le 13 Juil 2014
Hello, total beginner here. Working on fibonacci sequence and assignment says to indicate which numbers are a multiple of 3. Here's what I have:
function f=fibo(n)
if n<=1
f=1;
else
f=fibo(n-1)+fibo(n-2);
end
I want the output of my script to look like this vertically:
1
1
2
3 is a multiple of 3
5
8
...
I used a function m-file and have the answers displayed without the comment. I know I should use if and rem() to add the comment. So I want to attach the comment and also make my output a vertical list.
Thanks!

Réponses (1)

Image Analyst
Image Analyst le 13 Juil 2014
Use fprintf():
fprintf('This variable = %d\n', someValue);
You can display whatever text you want to the command window with fprintf().

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by