matlab - 如何通过 MATLAB GUI 中的滑块移动轴中的垂直线?
问题描述
我想通过滑块更改垂直线位置。代码如下。
function slider_wf_Callback(hObject, eventdata, handles)
% hObject handle to slider_wf (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global FLAG_DATA_LOADED;
if FLAG_DATA_LOADED == 1
slider_value = int32(get(hObject,'Value'));
set(handles.text_cur_frame_num, 'String',num2str(slider_value));
axes(handles.axes_waveform);
h = vline(slider_value/20, 'r-');
end
guidata(hObject, handles);
但是,当我移动滑块时,前面的行仍然存在。如何解决这个问题呢?
提前致谢。
解决方案
我没有 function vline
,但我假设它将句柄返回给 a Line
。您必须要么删除旧线并绘制新线,要么操纵现有线的位置。在这两种情况下,您都必须将手柄存放在某处。在 GUIDE 中,该handles
结构用于此目的。
这是删除旧的解决方案Line
:
if isfield(handles, 'myvline') % on the first run, no handle is available
delete(handles.myvline);
end
handles.myvline = vline(slider_value/20, 'r-');
% ...
guidata(hObject, handles); % important, used to update the handles struct
通过操纵现有的第二次尝试Line
if isfield(handles, 'myvline') % on the first run, no handle is available
handles.myvline.XData(:) = slider_value/20;
else
handles.myvline = vline(slider_value/20, 'r-');
end
% ...
guidata(hObject, handles); % important, used to update the handles struct
推荐阅读
- python-3.x - 如何为多对多字段(Python 3.9、Django 3)构建 YAML 数据?
- ios - 在 Api 请求参数错误中添加变量?
- excel - 仅在必要时在另一个表上输入值
- forms - 使用 POST 请求 -Svelte 未在 API 中填充表单数据
- android - AsyncTask 不从 postexecute 更新 UI
- ios - 根据推送通知从 Appdelegate 更改视图
- javascript - 2 javascript 对象事件处理程序交互
- node.js - lambda node.js 异步函数无法访问回调
- css - 减少两个标题标签之间的垂直间距
- java - 无法在 Android 9 和 10 中以编程方式重命名内部存储文件