QQ登录

只需要一步,快速开始

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

大家会吗?Matlab中的图形对象的选择

[复制链接]
字体大小: 正常 放大
回帖奖励 1 点体力 回复本帖可获得 1 点体力奖励! 每人限 1 次

413

主题

36

听众

1854

积分

升级  85.4%

  • TA的每日心情
    开心
    2019-9-18 21:55
  • 签到天数: 258 天

    [LV.8]以坛为家I

    社区QQ达人

    群组2015国赛冲刺

    群组2016美赛公益课程

    群组国赛讨论

    群组第三届数模基础实训

    群组Matlab讨论组

    跳转到指定楼层
    1#
    发表于 2015-10-11 19:23 |只看该作者 |倒序浏览
    |招呼Ta 关注Ta
                图形对象的选择
    在本例中的程序可以探测图形对象的属性,并显示如何用函数waitforbuttonpressgco选择对象。程序允许用户可以多次重复选择对象。
    % Script file: select_object.m
    %
    % Purpose:
    % This program illustrates the use of waitforbuttonpress
    % and gco to select graphics objects. It creates a plot
    % of sin(x) and cos(x), and then allows a user to select
    % any object and examine its properties. The program
    % terminates when a key press occurs.
    %
    % Record of revisions:
    % Date Programmer Description of change
    % ==== ========== =====================
    % 11/23/97 S. J. Chapman Originalcode
    %
    % Define variables:
    % details -- Object details
    % H1 -- Handle of sine line
    % H2 -- Handle of cosine line
    % Handle -- Handle of current object
    % k -- Result of waitforbuttonpress
    % type -- Object type
    % x -- Independent variable
    % y1 -- sin(x)
    % y2 -- cos(x)
    % yn -- Yes/No
    % Calculate sin(x) and cos(x)
    x = -3*pi:pi/10:3*pi;
    y1 = sin(x);
    y2 = cos(x);
    % Plot the functions.
    H1 = plot(x,y1);
    set(H1,'LineWidth',2);
    hold on;
    H2 = plot(x,y2);
    set(H2,'LineWidth',2,'LineStyle',':','Color','r');
    title('\bfPlot of sin \itx \rm\bf and cos \itx');
    xlabel('\bf\itx');
    ylabel('\bfsin \itx \rm\bf and cos \itx');
    legend('sine','cosine');
    hold off;
    % Now set up a loop and wait for a mouse click.
    k = waitforbuttonpress;
    while k == 0
        % Get the handle of theobject
        Handle = gco;
        % Get the type of thisobject.
        type = get(Handle,'Type');
        % Display object type
        disp (['Object type = 'type '.']);
        % Do we display thedetails?
        yn = input('Do you want todisplay details? (y/n) ','s');
        if yn == 'y'
            details = get(Handle);
            disp(details);
        end
        % Check for another mouseclick
        k = waitforbuttonpress;
    end


    图9.5 sinx和cosx的图象。.JPG (100.03 KB, 下载次数: 135)

    图9.5 sinx和cosx的图象。.JPG

    zan
    转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
    数学中国版主团队!

    413

    主题

    36

    听众

    1854

    积分

    升级  85.4%

  • TA的每日心情
    开心
    2019-9-18 21:55
  • 签到天数: 258 天

    [LV.8]以坛为家I

    社区QQ达人

    群组2015国赛冲刺

    群组2016美赛公益课程

    群组国赛讨论

    群组第三届数模基础实训

    群组Matlab讨论组

    1. % Script file: select_object.m
    2. %
    3. % Purpose:
    4. % This program illustrates the use of waitforbuttonpress
    5. % and gco to select graphics objects. It creates a plot
    6. % of sin(x) and cos(x), and then allows a user to select
    7. % any object and examine its properties. The program
    8. % terminates when a key press occurs.
    9. %
    10. % Record of revisions:
    11. % Date Programmer Description of change
    12. % ==== ========== =====================
    13. % 11/23/97 S. J. Chapman Original code
    14. %
    15. % Define variables:
    16. % details -- Object details
    17. % H1 -- Handle of sine line
    18. % H2 -- Handle of cosine line
    19. % Handle -- Handle of current object
    20. % k -- Result of waitforbuttonpress
    21. % type -- Object type
    22. % x -- Independent variable
    23. % y1 -- sin(x)
    24. % y2 -- cos(x)
    25. % yn -- Yes/No
    26. % Calculate sin(x) and cos(x)
    27. x = -3*pi:pi/10:3*pi;
    28. y1 = sin(x);
    29. y2 = cos(x);
    30. % Plot the functions.
    31. H1 = plot(x,y1);
    32. set(H1,'LineWidth',2);
    33. hold on;
    34. H2 = plot(x,y2);
    35. set(H2,'LineWidth',2,'LineStyle',':','Color','r');
    36. title('\bfPlot of sin \itx \rm\bf and cos \itx');
    37. xlabel('\bf\itx');
    38. ylabel('\bfsin \itx \rm\bf and cos \itx');
    39. legend('sine','cosine');
    40. hold off;
    41. % Now set up a loop and wait for a mouse click.
    42. k = waitforbuttonpress;
    43. while k == 0
    44.     % Get the handle of the object
    45.     Handle = gco;
    46.     % Get the type of this object.
    47.     type = get(Handle,'Type');
    48.     % Display object type
    49.     disp (['Object type = ' type '.']);
    50.     % Do we display the details?
    51.     yn = input('Do you want to display details? (y/n) ','s');
    52.     if yn == 'y'
    53.         details = get(Handle);
    54.         disp(details);
    55.     end
    56.     % Check for another mouse click
    57.     k = waitforbuttonpress;
    58. end
    复制代码

    数学中国版主团队!
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册地址

    qq
    收缩
    • 电话咨询

    • 04714969085
    fastpost

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

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

    蒙公网安备 15010502000194号

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

    GMT+8, 2026-1-2 12:26 , Processed in 0.711480 second(s), 58 queries .

    回顶部