0

Possible Duplicate:
How to save contents of MATLAB’s command windows to in a file?

Using function pretty(x) I get what I want in command window. I need to get the same in text file. How to do this?

Community
  • 1
  • 1
  • Look for [how do I write text files in matlab](http://stackoverflow.com/questions/9598132/how-do-i-write-to-a-text-file-in-matlab). This question has been asked many times before. – angainor Oct 11 '12 at 09:14
  • 1
    I guess the main problem is not writing to text file, but to store the output of `pretty` in a string. If so, please see: http://stackoverflow.com/questions/5833356/how-to-save-contents-of-matlabs-command-windows-to-in-a-file – H.Muster Oct 11 '12 at 09:18
  • Ways to do this are covered in [my answer](http://stackoverflow.com/a/5833389/52738) to the question @H.Muster linked to, so this is basically a duplicate. I also added another option to my answer that uses EVALC. – gnovice Oct 11 '12 at 18:49

2 Answers2

1

I think that the best way is to use the clc disp() and char() commands:

clc % clear the command window
syms x y;
expression = x*y; % make your calculations
expression2 = x+y;% make your calculations
                  % make your calculations
disp(char(expression)) % char() converts symbolic expression to string
disp(char(expression2))% and disp() shows the string in the command window

You can copy everything in the command window really fast with the normal windows commands ctrl+a (select all), ctrl+c (copy) and ctrl+v (paste).

Hope this helps

ljs.dev
  • 4,449
  • 3
  • 47
  • 80
jespestana
  • 565
  • 5
  • 13
1

You can use the command evalc to redirect all output that would go to the console to a string variable (which you later can save to a file).

E.g.:

>> a = sym('a'); b = sym('b');
>> str = evalc('pretty(a+b)');
>> str 

str =


  a + b
Andreas H.
  • 5,557
  • 23
  • 32