Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-14, 20:38   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 在MATLAB GUI函数的末尾更新列表框并将变量更改为旧值

下面的GUI只是在列表框中列出了一些数据,对其进行了绘制,并为用户提供了从列表框中删除条目的选项。在用户删除条目后(试图运行该条目时,它应该很明显),我被撞到墙上,试图使列表框正确更新。

我遇到的两个问题是:
  1. 虽然按钮的回调确实确实从数组x正确删除了该条目,但回调完成后,数组x会还原回原始x数组(因此,值会以某种方式恢复自身)。
  2. 我尝试使用“ drawnow”刷新列表框以反映当前的x数组(已被修改,至少在下面发出drawow的位置)。虽然没有任何变化。如何使用新的x数组值刷新列表框?
---------------- GUI代码---------

function testgui clear; close all; % Create the data x = (10:20)'; % example data % Create a figure f = figure('Name', 'GUI Test',... 'NumberTitle', 'off',... 'MenuBar', 'none',... 'Units', 'pixels',... 'Position', [100 100 700 800],... 'Visible', 'off'); % Create a set of axes a = axes('Parent', f,... 'Units', 'pixels',... 'Position', [230 50 450 700]); % Create a pushbutton for modifying x array pb_x = uicontrol('Style', 'pushbutton', ... 'Parent', f,... 'String', 'Delete Selection',... 'Units', 'pixels',... 'Position', [50 7 100 35],... 'Callback', @pb_change_x); plot(x,'bo'); % graph xlabel('Index Number'); ylabel('Variable x'); % Create a listbox to hold the x values y=strtrim(cellstr(num2str(x))); lb = uicontrol('Style', 'listbox',... 'Parent', f,... 'String', y,... 'Units', 'pixels',... 'Position', [50 50 100 700],... 'Callback', @list_change); set(f,'Visible','on') function list_change(varargin) % Runs when the selection in listbox is changed curIdx = get(lb,'Value'); % Index the value curVal = str2double(cell2mat(y(curIdx))); % Get position of curVal in x posVal = find(ismember(x,curVal)); % Clear all the children currently on the axes delete(get(a,'Children')) % Plot the one data point of interest plot(posVal,curVal,'bo','MarkerFaceColor','b','MarkerSize',10) xlabel('Index Number'); ylabel('Variable x'); % Plot all the data hold on plot(x,'bo') hold off end function pb_change_x(varargin) % Runs when DUT
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 03:00


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.