matlab hpopup2,e2h.m · octopus/spatialmath-matlab - Gitee.com

%E2H Euclidean to homogeneous

%

% H = E2H(E) is the homogeneous version (K+1xN) of the Euclidean

% points E (KxN) where each column represents one point in R^K.

%

% Reference::

% - Robotics, Vision & Control: Second Edition, P. Corke, Springer 2016; p604.

%

% See also H2E.

% Copyright (C) 1993-2019 Peter I. Corke

%

% This file is part of The Spatial Math Toolbox for MATLAB (SMTB).

%

% Permission is hereby granted, free of charge, to any person obtaining a copy

% of this software and associated documentation files (the "Software"), to deal

% in the Software without restriction, including without limitation the rights

% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies

% of the Software, and to permit persons to whom the Software is furnished to do

% so, subject to the following conditions:

%

% The above copyright notice and this permission notice shall be included in all

% copies or substantial portions of the Software.

%

% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS

% FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR

% COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER

% IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN

% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

%

% https://github.com/petercorke/spatial-math

function h = e2h(e)

h = [e; ones(1,numcols(e))];

一键复制

编辑

Web IDE

原始数据

按行查看

历史

作为一种高级的科学计算工具,Matlab 在很多方面都得到了广泛的应用,其中界面编程是其应用领域之一。以下面这个实例来说明如何搞定 Matlab 界面编程。 假设有这样一个问题:用户需要输入两个矩阵,然后选择一个运算符(如加、减、乘等),进行相应的运算。为了实现这样的功能,我们需要编写一个 Matlab 程序,其中涉及到界面编程。 首先,我们需要创建一个 Matlab 程序的界面,代码如下: ```matlab function calculator % 这个函数创建了一个用于计算加、减、乘、除的GUI f = figure('Visible','off','Position',[360,500,450,285]); % 创建一个输入框,用于输入第一个矩阵 hmatrix1 = uicontrol('Style','edit','Position',[75,240,200,25]); % 创建一个输入框,用于输入第二个矩阵 hmatrix2 = uicontrol('Style','edit','Position',[75,200,200,25]); % 创建一个下拉菜单,用于选择运算符 hpopup = uicontrol('Style','popupmenu','String', ... {'+','-', '*', '/'}, ... 'Position',[75,160,100,25]); % 创建一个按钮,用于触发计算事件 hbutton = uicontrol('Style','pushbutton','String','计算', ... 'Position',[75,120,100,25],'Callback',{@calculate_Callback}); % 创建一个静态文本,用于显示计算结果 hresult = uicontrol('Style','text','BackgroundColor','white',... 'Position',[75,80,200,25]); % 将窗口设置为可见 set(f,'Visible','on'); % 计算函数的回调函数 function calculate_Callback(source,eventdata) % 获取输入框中输入的数据 matrix1 = str2num(get(hmatrix1,'String')); matrix2 = str2num(get(hmatrix2,'String')); % 获取选中的运算符 str = get(hpopup, 'String'); val = get(hpopup,'Value'); operator = str{val}; % 进行矩阵运算,并将结果显示出来 if operator == '+' result = matrix1 + matrix2; elseif operator == '-' result = matrix1 - matrix2; elseif operator == '*' result = matrix1 * matrix2; elseif operator == '/' result = matrix1 / matrix2; end set(hresult,'String',result); end end ``` 这个程序创建了一个界面,包含了输入框、下拉菜单、按钮和静态文本等。其中,输入框用于输入矩阵,下拉菜单用于选择运算符,按钮用于启动计算事件,静态文本用于显示计算结果。 当用户点击计算按钮时,回调函数 calculate_Callback 会被执行。在这个函数中,我们先获取输入框中输入的矩阵数据和选中的运算符,然后进行相应的运算并将结果显示在静态文本中。 总的来说,这个实例介绍了如何利用 Matlab 进行界面编程,包括创建界面、添加控件和设置回调函数等。对于初学者来说,这是一个不错的入门教程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值