How can i get multiple values in fprintf?

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...

 채택된 답변

KSSV
KSSV 2018년 4월 11일

0 개 추천

n = [1, 2, 3];
fprintf('I have numbers: %s\n', sprintf('%d ', n))

댓글 수: 3

JJ
JJ 2018년 4월 11일
Thanks, I knew it must be something simple but just couldn't seem to think of it
JJ
JJ 2018년 4월 11일
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 2018년 4월 11일
Its ok I have it now thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

JJ
2018년 4월 11일

댓글:

JJ
2018년 4월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by