Hello all, I have a code which calculates 2 values,one for a1=1217 and the other is for a2=-845.42. Although the code is working correctly, the end results comes as:
a1 & a2=
1217
-845.42
How can I display the end results as:
a1=1217
a2=-845.42
The code for reporting I used is :
disp('a1 & a2='); disp(a)
% where a=T\P;
I think I should use fprintf but I am not sure how.
I hope my question makes sense. Many thanks

 채택된 답변

Stephen23
Stephen23 2018년 9월 19일
편집: Stephen23 2018년 9월 19일

1 개 추천

>> a = [1217,-845.42];
>> fprintf('a1 = %g\na2 = %g\n',a)
a1 = 1217
a2 = -845.42

댓글 수: 3

D.J
D.J 2018년 9월 19일
This is exactly what I was looking for. Thanks a lot Stephen !
Stephen23
Stephen23 2018년 9월 19일
@D.J: that's great! Remember to accept my answer!
D.J
D.J 2018년 9월 19일
Sorry, just did...

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

추가 답변 (1개)

KSSV
KSSV 2018년 9월 19일

0 개 추천

a1 = rand ;
a2 = rand ;
fprintf('a1 = %f, a2 = %f\n',a1,a2)

카테고리

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

질문:

D.J
2018년 9월 19일

댓글:

D.J
2018년 9월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by