MATLAB Answers

Z

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

Asked by Z
on 18 Jun 2013

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!

  0 Comments

Products

No products are associated with this question.

2 Answers

Answer by Pourya Alinezhad on 18 Jun 2013
Edited by Pourya Alinezhad on 18 Jun 2013
 Accepted answer
disp(['rate:',num2str(rate),'duration:',num2str(duration)])

  3 Comments

Z
on 18 Jun 2013

Thanks! Let me try this.

Z
on 18 Jun 2013

awesomeness. thanks

Pourya Alinezhad on 18 Jun 2013

;) take the advantage


Answer by Elliot Olsen
on 18 Jun 2013

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 Comment

Z
on 18 Jun 2013

This also works great! And there are spaces too. Thanks


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today