3/26/2008

matlab中semicolon(分号)的巨大作用

To make Matlab give an output, such as return the value of a variable, you type the name of the variable without any semicolon (;) following the variable.
如果需要显示的话,不要加分号
In many cases, there is no need to see the value of a variable every single time Matlab uses it. If Matlab re-computes the value of a variable 1000 times, we probably don't want to see the result every single time. To surpress the output of a value, just add a semi colon after the variable. Then Matlab will perform the command, but will not show it on the screen.
不需要显示中间过程的话,加上分号.

例子
%solve linear equations

clear;
diary hw6prob2.txt;
fprintf('This just shows 5*5 matrix but 100*100 is basically the same.\n');
fprintf('The result for 100*100 matrix is just too large to show on one paper.\n');
N=5;
for j=1:N,
for i=1:N,
A(i,j) = 1/(i+j-1);//这里需要加上分号,这样可以不显示中间过程
end
end

for n=1:N;
B(n,1)=1/n;
end

A, //这里需要显示结果,所以不能加分号
B,

X=A\B;
fprintf('The solution for this linear equation is: \n ');
X,

diary off;

没有评论: