我需要在我的绘图附近创建滑块,与其参数进行交互。 有人可以解释一下如何在同一个图中创建它,将滑块参数的名称和值放在它附近以及如何将它与我的情节链接?
感谢。
答案 0 :(得分:3)
查看demo_uicontrol.m,其中包含您所需要的一切:
一个剥离的例子,说明你在我的情节附近提出的问题"滑块"
## Useful since Octave 4.0
close all
clear h
graphics_toolkit qt
h.ax = axes ("position", [0.05 0.42 0.5 0.5]);
function update_plot (obj, init = false)
## gcbo holds the handle of the control
h = guidata (obj);
a = get (h.slider1, "value");
w = get (h.slider2, "value");
x = linspace (0, 3);
y = a * sin (x * 5 * w);
if (init)
h.plot = plot (x, y, "b");
else
set (h.plot, "xdata", x);
set (h.plot, "ydata", y);
endif
guidata (obj, h);
endfunction
h.slider1 = uicontrol ("style", "slider",
"units", "normalized",
"string", "slider",
"callback", @update_plot,
"value", 0.4,
"position", [0.05 0.25 0.35 0.06]);
h.slider2 = uicontrol ("style", "slider",
"units", "normalized",
"string", "slider",
"callback", @update_plot,
"value", 0.7,
"position", [0.05 0.15 0.35 0.06]);
set (gcf, "color", get(0, "defaultuicontrolbackgroundcolor"))
guidata (gcf, h)
update_plot (gcf, true);