码迷,mamicode.com
首页 > 其他好文 > 详细

用MATLAB绘制的一个单词“LOVE”的图像

时间:2014-11-12 23:13:40      阅读:665      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   color   ar   os   sp   for   strong   

APEC放假最后一天啦,在家里鼓捣MATLAB,突然想到用MATLAB里的函数图像画一个好玩的东西。想来想去,就画成了这个样子:

bubuko.com,布布扣

这个图像是由以下四个方程的图像构成的

1)y=1/(x+4.5)-4.5

2)((x+2)/1.5)^2+(y/2.5)^2=1

3)y=|-4x+5|-1

4)x=-2.1|sin(y)|+4.6

制作的方式如下

1)在MATLAB程序中上方的菜单中选择 New→Script

2)在脚本界面输入下面的代码,保存到DrawStringLove.m

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]);

end

3)在代码编辑器(Editor)上方的菜单中点击按钮Run,如果没有添加路径,MATLAB会询问是否把这个脚本文件添加到路径中,单击“Add Path”按钮即可。成功运行。

把*.m文件制作成*.exe的方法如下:

1)在控制台输入deploytool,这时会弹出一个菜单

bubuko.com,布布扣

在New里面输入test.prj,然后单击OK按钮

2)如果之前创建过*.prj项目,则在Open选项卡中直接选择

bubuko.com,布布扣

3)把之前保存的脚本文件(DrawStringLove.m)加载进来,然后单击Build按钮

bubuko.com,布布扣

4)在这个窗口中的Detail中,可以看到exe文件保存的地址

bubuko.com,布布扣

本次生成的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中就找到最后生成的可执行文件

bubuko.com,布布扣

注意:这个exe文件只能用安装了MATLAB的计算机运行,否则会报错

END

用MATLAB绘制的一个单词“LOVE”的图像

标签:style   http   io   color   ar   os   sp   for   strong   

原文地址:http://my.oschina.net/Tsybius2014/blog/343701

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!