matlab怎样交互,如何使MATLAB图交互? | 码农网

好的,我从图像处理工具箱中搜索了有关ImPoint选项的更多信息,并写了这个脚本.

由于ImPoint仅适用于2D设置(我想将其归结为3D,以便能够使用曲面而不是曲线),这并不是一个可以接受的答案!但有人可能会从中受益,或者想出如何在3D中做到这一点.

% -------------------------------------------------

% This file needs the Image Processing Toolbox!

% -------------------------------------------------

function Interact(Pos)

% This part is executed when you run it for the first time.

% In that case, the number of input arguments (nargin) == 0.

if nargin == 0

close all;

clear all;

clc;

figure();

hold on;

axis([0 7 0 5])

% I do not know how to do this without global variables?

global P0 P1 P2

% GCA = Get handle for Current Axis

P0 = ImPoint(gca,1,1);

setString(P0,'P0');

P1 = ImPoint(gca,2,4);

setString(P1,'P1');

P2 = ImPoint(gca,6,2);

setString(P2,'P2');

% Call subfunction

DrawLagrange(P0,P1,P2)

% Add callback to each point

addNewPositionCallback(P0,@Interact);

addNewPositionCallback(P1,@Interact);

addNewPositionCallback(P2,@Interact);

else

% If there _is_ some input argument, it has to be the updated

% position of a moved point.

global H1 H2 P0 P1 P2

% Display X and Y coordinates of moved point

Pos

% Important: remove old plots! Otherwise the graph will get messy.

delete(H1)

delete(H2)

DrawLagrange(P0,P1,P2)

end

function DrawLagrange(P0,P1,P2)

P = zeros(3,2);

% Get X and Y coordinates for the 3 points.

P(1,:) = getPosition(P0);

P(2,:) = getPosition(P1);

P(3,:) = getPosition(P2);

global H1 H2

H1 = plot(P(:,1), P(:,2), 'ko--', 'MarkerSize', 12);

t = 0:.1:2;

Lagrange = [.5*t.^2 - 1.5*t + 1; -t.^2 + 2*t; .5*t.^2 - .5*t];

CurveX = P(1,1)*Lagrange(1,:) + P(2,1)*Lagrange(2,:) + P(3,1)*Lagrange(3,:);

CurveY = P(1,2)*Lagrange(1,:) + P(2,2)*Lagrange(2,:) + P(3,2)*Lagrange(3,:);

H2 = plot(CurveX, CurveY);

为了清楚起见,我添加了一些意见.

[编辑]在预览中,语法高亮不是很好!我应该定义哪个语言被突出显示在某个地方吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值