我有一个关于Matlab选择以PDF格式发布的问题。说我有以下代码:
%1D functions and plotting
%1. We calculate y given the following function: y(x) = 2x^2 +
%3x + 1, for x = 10.
x = 10;
y = 2*x.^2 + 3*x + 1
%2. We calculate y given the following function: y(x) = ax^2 + bx + c, with a
%=2, b=3, c=0 and x = 100.
a=2;
b=3;
c=0;
x=100;
y = a*x.^2 + b*x + c
. . . more code follows here
当我选择将其作为PDF发布时,问题1和2(我为变量'y'计算两个不同的值)的答案不会出现在我计算值的行(我在哪里写{{1 }} 例如)。相反,'y'变量的值出现在文档的末尾,表示'y = 231'和'y = 20300'。有没有办法在我定义变量而不将文档分成单元格后立即将其包含在内?或者这是一个我无法做任何事情的默认事情?我真的很感激任何意见!
答案 0 :(得分:1)
一般方法(独立于输出格式)是重新启动段落,换行符和%%
:
%% 1. We calculate y given the following function: y(x) = 2x^2 +
% 3x + 1, for x = 10.
x = 10;
y = 2*x.^2 + 3*x + 1
%% 2. We calculate y given the following function: y(x) = ax^2 + bx + c, with a
% =2, b=3, c=0 and x = 100.
a=2;
b=3;
c=0;
x=100;
y = a*x.^2 + b*x + c