APEC放假最後一天啦,在家裏鼓搗MATLAB,忽然想到用MATLAB裏的函數圖像畫一個好玩的東西。想來想去,就畫成了這個樣子:app
這個圖像是由如下四個方程的圖像構成的編輯器
1)y=1/(x+4.5)-4.5函數
2)((x+2)/1.5)^2+(y/2.5)^2=1ui
3)y=|-4x+5|-1spa
4)x=-2.1|sin(y)|+4.6ip
製做的方式以下:ci
1)在MATLAB程序中上方的菜單中選擇 New→Scriptit
2)在腳本界面輸入下面的代碼,保存到DrawStringLove.mio
function DrawStringLove()
figure('NumberTitle', 'off', 'Name', 'TEST 2014/11/12 Wed'); %設置窗口名
clear all;
clc;
hold on; %繪圖前圖像不刷新
grid on; %打開網格
title('Hello World!'); %設置圖像標題
set(gca, 'color', [0.5, 0.5, 0.5]); %設置plot背景色
%繪製圖像:y=1/(x+4.5)-4.5
x1 = -5 : 0.01 : 5;
y1 = 1 ./ (x1 + 4.5) - 4.5;
plot(x1, y1, 'r', 'linewidth', 5); %r表明紅色,linewidth設置線寬爲5
%繪製圖像:((x+2)/1.5)^2+(y/2.5)^2=1
alpha = 0 : pi / 50 : 2 * pi;
x2 = 1.5 * cos(alpha) - 2;
y2 = 2.5 * sin(alpha);
plot(x2, y2, 'b', 'linewidth', 5); %b表明藍色
%繪製圖像:y=|-4x+5|-1
x3 = -5 : 0.01 : 5;
y3 = -4 * x3 + 5;
y3 = abs(y3) - 1;
plot(x3, y3, 'g', 'linewidth', 5); %g表明綠色
%繪製圖像:x=-2.1|sin(y)|+4.6
x4 = -3.2 : 0.01 : 3.2;
y4 = -2.1 * abs(sin(x4)) + 4.6;
plot(y4, x4, 'y', 'linewidth', 5); %y表明黃色
axis([-5,5,-5,5]);
endfunction
3)在代碼編輯器(Editor)上方的菜單中點擊按鈕Run,若是沒有添加路徑,MATLAB會詢問是否把這個腳本文件添加到路徑中,單擊「Add Path」按鈕便可。成功運行。
把*.m文件製做成*.exe的方法以下:
1)在控制檯輸入deploytool,這時會彈出一個菜單
在New裏面輸入test.prj,而後單擊OK按鈕
2)若是以前建立過*.prj項目,則在Open選項卡中直接選擇
3)把以前保存的腳本文件(DrawStringLove.m)加載進來,而後單擊Build按鈕
4)在這個窗口中的Detail中,能夠看到exe文件保存的地址
本次生成的Detail以下:
ant:
<mkdir dir="D:\MATLAB\R2013a\bin\test\distrib" />
<mkdir dir="D:\MATLAB\R2013a\bin\test\src" />
mcc -o test -W WinMain:test -T link:exe -d D:\MATLAB\R2013a\bin\test\src -w enable:specified_file_mismatch -w enable:repeated_file -w enable:switch_ignored -w
enable:missing_lib_sentinel -w enable:demo_license -v D:\MATLAB\script\DrawStringLove.m
Compiler version: 4.18.1 (R2013a)
Processing D:\MATLAB\R2013a\toolbox\matlab\mcc.enc
Processing D:\MATLAB\R2013a\toolbox\shared\spcuilib\mcc.enc
Processing include files...
2 item(s) added.
Processing directories installed with MCR...
The file D:\MATLAB\R2013a\bin\test\src\mccExcludedFiles.log contains a list of functions excluded from the CTF archive.
0 item(s) added.
Generating MATLAB path for the compiled application...
Created 44 path items.
Begin validation of MEX files: Wed Nov 12 17:20:00 2014
End validation of MEX files: Wed Nov 12 17:20:00 2014
Warning: Adding path "D:\MATLAB\script" to Compiler path instance.
Parsing file "D:\MATLAB\script\DrawStringLove.m"
(Referenced from: "Compiler Command Line").
Parsing file "D:\MATLAB\R2013a\toolbox\compiler\deploy\deployprint.m"
(Referenced from: "Compiler Command Line").
Parsing file "D:\MATLAB\R2013a\toolbox\compiler\deploy\printdlg.m"
(Referenced from: "Compiler Command Line").
Deleting 0 temporary MEX authorization files.
Generating file "D:\MATLAB\R2013a\bin\test\src\readme.txt".
copy 'D:\MATLAB\R2013a\bin\test\src\test.exe' 'D:\MATLAB\R2013a\bin\test\distrib\test.exe'
copy 'D:\MATLAB\R2013a\bin\test\src\readme.txt' 'D:\MATLAB\R2013a\bin\test\distrib\readme.txt'
5)在位置D:\MATLAB\R2013a\bin\test\distrib\test.exe中就找到最後生成的可執行文件
注意:這個exe文件只能用安裝了MATLAB的計算機運行,不然會報錯
END