matlab中gui界面制作的问题汇总

1、在gui里添加箭头

在这里插入图片描述

annotation('arrow',x,y)      % 建立从(x(1), y(1))(x(2), y(2))的箭头注释对象。

gui界面
添加箭头后

2、gui中的单选按钮

在这里插入图片描述

3、怎么从一个guide界面里面一个按钮打开另外一个guide界面

在按钮回调的函数中,键入所需的界面名称。这两个界面要放在同一个文件夹下。
在这里插入图片描述

h=gcf;
step1;%需要的界面
close(h);%关闭原界面

4、重置和退出代码

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% 重置清空图片 
cla(handles.axes1,'reset');
cla(handles.axes2,'reset');
cla(handles.axes3,'reset');
cla(handles.axes4,'reset');
cla(handles.axes5,'reset');

% 重置清空动态txt的文字 
set(handles.edit1,'string','')
set(handles.edit2,'string','')
set(handles.edit3,'string','')
set(handles.edit4,'string','')

%退出
close

5、进度条代码

        h=waitbar(0,'请稍等,正在开始读取文件...');
        while feof(fin)==0
           str=fgetl(fin);
            [name yuwen shuxue yingyu]=strread(str,'%s %d %d %d','delimiter',' ');
           xingming(counter)=name;
           chengji(counter-1,:)=[yuwen shuxue yingyu];
           counter=counter+1;
           waitbar(counter/counter+1,h,'请稍等...');
        end;
        waitbar(1,h,'已完成');

6、三维图显示出来可旋rrotate

rotate3d on;

7、根据弹出对话框的值,改变界面中“可编辑文本框”的内容

answer=inputdlg('f1 , f2 , f3','填写三个频率',1,{'[70 64 59]'});
rect1=answer{1,1};
rect2=str2sym(rect1);
f=double(rect2);
f11=f(1);
f22=f(2);
f33=f(3);
f22=num2str(f22)
f222=strcat('f2=',f22);
set(handles.f1,'string',num2str(f11));%只能显示“70set(handles.f2,'string',f222);%可以显示“f2=64”,成功
set(handles.f3,'string',{'f3=',num2str(f33)});%失败

在这里插入图片描述

8、plot title 包含变量的图片标题

x=1:0.01:10;
y=sin(x);
plot(x,y,'linewidth',3)
xlabel('x')
ylabel('y')
x=2;
title(['mingzi',num2str(x)])%记得要加中括号

9、GUI 窗口初始最大化

参考:https://blog.csdn.net/miao0967020148/article/details/52450618

% --- Outputs from this function are returned to the command line.
function varargout = lzw_1_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%弹出窗口时最大化
 javaFrame = get(gcf,'JavaFrame');
 set(javaFrame,'Maximized',1); 
% Get default command line output from handles structure
varargout{1} = handles.output;

10、GUI中fig和m文件名修改流程及注意事项

参考https://blog.csdn.net/weixin_43211480/article/details/90547471

11、显示耗时/计算程序显示运行时间的几种方法

参考https://blog.csdn.net/lily1547772448/article/details/79773239
tic和toc组合

tic;
%代码块
toc;
disp(['运行时间: ',num2str(toc)]);

etime()与clock组合

 t1=clock;
 %代码块
 t2=clock;
 etime(t2,t1)

cputime函数

t0=cputime
%代码块
t1=cputime-t0

12、怎么获取下拉列表/弹出式菜单选中的值

val=get(handles.popupmenu2,'value');

switch val
    case 1   %第一个是标题  
        AddTime=1;
    case 2
        AddTime=10;
    case 3
        AddTime=20;
    case 4 
        AddTime=30;
    case 5
        AddTime=40;
end
disp(AddTime);

附录matlab中遇到的小问题

1、归一化和反归一化

参考https://www.cnblogs.com/Eumenides/p/8917145.html
三频外差的真实图片操作和模拟的不一样,期间用到了
一、归一化函数mapminmax()

  1、默认的归一化范围是(-1,1),使用mapminmax(data,0,1)将范围控制在(0,1)。

   2、按行归一化,矩阵则每行归一化一次。若要完全归一化,则

         FlattenedData = OriginalData(:)'; % 展开矩阵为一列,然后转置为一行。
         MappedFlattened = mapminmax(FlattenedData, 0, 1); % 归一化。
         MappedData = reshape(MappedFlattened, size(OriginalData)); % 还原为原始矩阵形式。此处不需转置回去,因为reshape恰好是按列重新排序

    例:A=(......)

           [B,PS]=mapminmax(A,0,1)

二、反归一化

   A=mapminmax('reverse',B,PS)

2、以三维的方式显示灰度图像

原文链接:https://blog.csdn.net/q1302182594/article/details/51039564

img = imread('F:\相册\psu_gray.png');               
[y,x] = size(img);                 % 取出图像大小
[X,Y] = meshgrid(1:x,1:y);         % 生成网格坐标
pp = double(img);                  % uint8 转换为 double 
mesh(X, Y, pp);                    % 画图
colormap gray;                     % 选为灰度
  • 11
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值