matlab的gui,怎么在同一个axes用两个button切换两张不同的图片

**

matlab的gui,怎么在同一个axes用两个button切换两张不同的图片

**

本人在学习图像处理的过程中遇到了这个问题,上网也没找到点啥解决办法,可能是我太菜了,不过还好,突然想到能解决的办法,好歹算是解决了,下面说一下我开始遇到的情况以及解决办法,如果有大佬能有更好的办法欢迎留言。

对了,我的matlab是r2017a不知道其他的会不会有这个问题

再ps,这个说的是matlab 的gui,如果是初学者可以看b站这个视频,讲的还挺不错的


一开始,我想用两个axes

在axes1中imshow(‘01.jpg’),然后再axes2中imshow(‘02.jpg’),并且将axes2的visible调整为off,这样从表面上就只能看到axes1,然后就可以用button来回切换axes1和axes2的visible属性,让一个可见一个不可见

经过测试发现,button回调函数写的是正确的,但是就是不能实现来回切换功能,然后我把axes2放空,发现axes1里在imshow之后,imshow的图片会跑到最顶层来,然后不断按下button会让axes2里的空坐标系出现在图片的后方。就和word里面的图片置于顶层一样,但关键是我还找不到能调整顶层底层的属性

后来还想了干脆在同一个坐标系里删掉重画算了,反正自己用的,但是又想了想太浪费运算了,还要耗时间等个1、2秒

再然后

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个实现该功能的 MATLAB GUI 代码: ```matlab function save_button_Callback(hObject, eventdata, handles) % --- Executes on button press in save_button. % Saves the current axes image with its coordinates and legend to a file. % Get the axes handle and the legend handle axes_handle = handles.axes1; legend_handle = handles.legend1; % Get the axes limits and the legend string x_limits = xlim(axes_handle); y_limits = ylim(axes_handle); legend_string = get(legend_handle, 'String'); % Create a new figure to save the image fig_handle = figure('Visible', 'off'); new_axes_handle = copyobj(axes_handle, fig_handle); % Set the new axes limits and legend string xlim(new_axes_handle, x_limits); ylim(new_axes_handle, y_limits); legend(new_axes_handle, legend_string); % Save the image as a PNG file [filename, pathname] = uiputfile('*.png', 'Save Image As'); if ~(isequal(filename, 0) || isequal(pathname, 0)) full_path = fullfile(pathname, filename); print(fig_handle, full_path, '-dpng', '-r300'); end % Close the new figure close(fig_handle); end ``` 该函数会获取 GUI 中的 `axes` 和 `legend` 句柄,然后获取 `axes` 的坐标范围和 `legend` 的字符串。接着,它会创建一个新的图形窗口,并将 `axes` 和 `legend` 复制到该窗口中。在新的 `axes` 中,它会设置坐标范围和 `legend` 字符串。最后,它将该图像保存为 PNG 文件。 你需要将该函数与 GUI 中的保存按钮关联起来。可以使用 GUIDE 工具或手动编写代码来实现。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值