QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 1103|回复: 0
打印 上一主题 下一主题

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

[复制链接]
字体大小: 正常 放大

398

主题

13

听众

1339

积分

  • TA的每日心情
    慵懒
    2015-12-12 14:33
  • 签到天数: 81 天

    [LV.6]常住居民II

    跳转到指定楼层
    1#
    发表于 2015-10-10 23:27 |只看该作者 |倒序浏览
    |招呼Ta 关注Ta

    效果图:


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

    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,这时会弹出一个菜单

    在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




    zan
    转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
    您需要登录后才可以回帖 登录 | 注册地址

    qq
    收缩
    • 电话咨询

    • 04714969085
    fastpost

    关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

    手机版|Archiver| |繁體中文 手机客户端  

    蒙公网安备 15010502000194号

    Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

    GMT+8, 2025-5-18 09:26 , Processed in 0.293237 second(s), 53 queries .

    回顶部