2

In matlab, evaluating a variable without a semicolon causes it to be printed on the console output. disp is similar but does not include the variable name. Is there a way to get either console output as a string?

e.g.

>> x = [-1; 2];
>> x

x =

    -1
     2 

Is there a way to get this output assigned to a variable in a string, i.e. in this example the string "x = \n\n -1\n 2\n"

2
  • 1
    Why just out of curiosity Commented Sep 5, 2016 at 5:29
  • @MadPhysicist Good point, I cannot think of any good reason that you want to do this. Commented Sep 5, 2016 at 6:56

1 Answer 1

3
x=[1;2]
s=evalc('x')

Then s='\nx =\n\n 0\n 1'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.