matlab 学习之一

关于在自然图像上画散点的操作

显示首先得显示图像

figure

imshow(‘img’) 

hold on %这个很重要,要不然接下来的画图操作就不会画在自然图上了。

for i=1:numel(x)
    a(i) = floor(x(i)/640);
    b(i) = x(i) - a(i)*640;    
end
plot(a,b,'r.');
set(gca,'xlim',[0,639]);   %设置x方向的坐标
set(gca,'ylim',[0,479]);   %设置y方向的坐标
hold off


关于获得图像的句柄(handle)

昨天上网查了好久也没对获得图像的句柄看出个所以然来,忽然灵机一动原来可以这样获得句柄

handle = imshow('img');

然后再对这个句柄去操作。

我接下来的操作是进行鼠标在图像上滑过可以实时显示图像的坐标,

代码如下:

可以采用调用下面的函数来实现这一功能

dypoint(handle); %只需要传递一个参数


(转载的)

function dynpoint(arg,h) 
% Show the coordinates of a plot dynamically 

% To start use: 
% dynpoint(h) 
% where h is a handle to a figure, axes or e.g. line. 

% To delete use: 
% dynpoint('delete',h) 
% where h is a handle to a figure, axes or e.g. line. 
% (you may also use: dynpoint delete) 

% There can only be one dynamic plotter in a figure at a time. 

% Example: 
% subplot(211), hline = plot(sin(1:10)) 
% subplot(212), plot(sin(1:100)) 
% dynpoint(hline) 


% 2002,6.29 


if ~exist('arg','var') 
arg = gcf; 
end 


if ~isstr(arg) 
handle = arg; 
arg = 'init'; 
end 


switch arg 
case 'init' 
if ~ishandle(handle) 
error('h is not a handle') 
end 


[h,ax] = h2hax(handle); 


% delete old dynamic text object 
ht = findobj(h,'tag',[mfilename '_text']); 
if any(ht) 
delete(ht) 
end 


% text window at the bottom left corner 
% text in centred 
uicontrol(h,... 
'style','text',... 
'pos',[2 2 200 15],... 
'tag',[mfilename '_text'],... 
'userdata',ax(1)) 


% do the dynamic thing... 
set(h,'windowbuttonmotionfcn',[mfilename ' move']) 


case 'move' 
ht = findobj(gcbf,'tag',[mfilename '_text']); 
ax = overobj('axes'); 
if ~any(ax) 
ax = get(ht,'userdata'); 
end 
p = get(ax,'currentpoint'); 
set(ht,'string',sprintf('(%g, %g)', p(1), p(3))); 


case 'delete' 
if ~exist('h','var') 
h = gcf; 
end 
[h,ax] = h2hax(h); 
set(h,'windowbuttonmotionfcn','') 


ht = findobj(h,'tag',[mfilename '_text']); 
delete(ht) 


end 


% ---------- 
function [h,ax]=h2hax(handle) 


typ = get(handle,'type'); 
if strcmp(typ,'figure') 
h = handle; 
ax = findobj(h,'type','axes'); 
elseif strcmp(typ, 'axes') 
h = get(handle,'parent'); 
ax = handle; 
elseif strcmp( get(get(handle,'parent'), 'type'), 'axes' ) 
ax = get(handle,'parent'); 
h = get(ax,'parent'); 
end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Matlab学习路线可以按照以下步骤进行: 1. 简介:首先,了解Matlab的基本概念和用途。Matlab是一种用于科学计算和工程应用的高级编程语言和交互式环境。它可以用于进行矩阵计算、数据可视化、算法开发和其他各种工程任务。你可以通过阅读相关的介绍和文档来对Matlab有一个初步的了解。 2. 安装:在学习Matlab之前,你需要安装Matlab软件。可以按照Matlab编程安装教程的详细步骤来完成安装。安装完成后,你就可以开始学习Matlab编程了。 3. 入门指南:为了帮助初学者快速入门Matlab编程,可以参考一些入门指南和教程。这些指南通常会包括Matlab的基本语法、变量、运算符、控制流程和函数等内容。通过学习这些基础知识,你可以建立起对Matlab编程的基本理解和应用能力。 4. 案例分析:学习Matlab编程的一个重要方法是通过案例分析来实践。可以选择一些与数学统计相关的案例,如柱状图、曲线分析等,并学习如何使用Matlab来实现这些功能。这样可以帮助你将所学的知识应用到实际问题中,提高编程能力和解决问题的能力。可以参考Matlab编程语言应用之数学统计的使用方法简介和案例实现等资料。 总结起来,Matlab学习路线包括了简介、安装、入门指南和案例分析。通过系统地学习这些内容,你可以逐步提高自己的Matlab编程能力,为科学计算和工程应用做好准备。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值