How can i get multiple values in fprintf?

1 view (last 30 days)
JJ
JJ on 11 Apr 2018
Commented: JJ on 11 Apr 2018
So i have 'n' lots of integers every time I run the script. My code displays my fprintf n times...
fprintf('I have numbers: %d \n',numbers)
Is there a way to display all the 'n' numbers in the same line rather than repeating?
So I have if n=4
I have numbers: 1
I have numbers: 2
I have numbers: 3
I have numbers: 4
and I want:
I have numbers: 1,2,3,4
If I knew n i could put multiple %d 's in the fprintf.... but my n changes every time...

Accepted Answer

KSSV
KSSV on 11 Apr 2018
n = [1, 2, 3];
fprintf('I have numbers: %s\n', sprintf('%d ', n))
  3 Comments
JJ
JJ on 11 Apr 2018
Ok so my numbers are being calculated and change each time so like:
n=10
number=2*n
fprintf('I have numbers: %d \n',numbers)
JJ
JJ on 11 Apr 2018
Its ok I have it now thanks

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!