【问题标题】:MATLAB: pretty function and writing to file [duplicate]MATLAB:漂亮的函数并写入文件[重复]
【发布时间】:2012-10-11 09:07:06
【问题描述】:

可能重复:
How to save contents of MATLAB’s command windows to in a file?

使用函数pretty(x) 我在命令窗口中得到了我想要的。我需要在文本文件中得到相同的结果。如何做到这一点?

【问题讨论】:

标签: matlab


【解决方案1】:

您可以使用命令 evalc 将所有将发送到控制台的输出重定向到字符串变量(稍后您可以将其保存到文件中)。

例如:

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

str =


  a + b

【讨论】:

    【解决方案2】:

    我认为最好的方法是使用 clc disp() 和 char() 命令:

    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
    

    您可以使用普通的 Windows 命令快速复制命令窗口中的所有内容 ctrl+a(全选)、ctrl+c(复制)和 ctrl+v(粘贴)。

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-14
      • 2016-01-25
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 2018-06-12
      相关资源
      最近更新 更多