Attempt to execute SCRIPT plot as a function?

刚编写完一个简单的画图程序,代码如下

close all;
clc;
clear;
% sinx
x = linspace(0,2*pi,200);
f1 = sin(x);
plot(x,f1);

title('plot of f_1=sin(x)');
xlabel('x');
ylabel('f_1');
axis([0 2*pi -1.1 1.1]);

% cos(x)
f2 = cos(x);
figure;
plot(x,f2);
title('plot of f_2 = cos(x)');
xlabel('x');
ylabel('f_2');
axis([0 2*pi -1.1 1.1]);

% plot on the same pic
figure;
plot(x,f1,'-go')
hold on;
plot(x,f2,'-r^');
title('plots of f_1=sin(x),f_2 = cos(x)');
xlabel('x');
ylabel('f_1,f_2');
axis([0 2*pi -1.1 1.1]);

legend('f_1','f_2');

gtext('f_1 = f_2 at two places');

结果我将它保存为plot.m文件了,执行后一直出现?? Attempt to execute SCRIPT plot as a function这个提示,结果仔细查找了下原因是因为文件名取错了改为plot2D或者其它都可以了,不能用matlab内部自带的函数名来命名。

你可能感兴趣的:(function,matlab,plot)