Is it possible to combine strings and variables in a matrix?

조회 수: 4 (최근 30일)
Z
Z 2013년 6월 18일
I have a matrix A and A= [x y]. X and y are both defined by constants: 3 and 4, respectively.
Now, how do I make it so that I not only get A to show up as 3 4 but as x=3 and y=4.
I tried this A= ['x='x 'y='y] but it does not work.
Thanks!

채택된 답변

Pourya Alinezhad
Pourya Alinezhad 2013년 6월 18일
편집: Pourya Alinezhad 2013년 6월 18일
disp(['rate:',num2str(rate),'duration:',num2str(duration)])
  댓글 수: 3
Z
Z 2013년 6월 18일
awesomeness. thanks
Pourya Alinezhad
Pourya Alinezhad 2013년 6월 18일
;) take the advantage

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

추가 답변 (1개)

random09983492
random09983492 2013년 6월 18일
Hi Z,
Here are 2 solutions:
1. Change:
disp [rate, duration]
to:
disp([rate, duration])
2. Use fprintf statement instead of disp like such:
fprintf('rate = %d, duration = %d', rate, duration);
This will produce your "even better" result, I think. If not, let me know what you would like.
Elliot
  댓글 수: 1
Z
Z 2013년 6월 18일
This also works great! And there are spaces too. Thanks

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

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by