使用单选按钮面板选择不同的绘图选项
我正在尝试创建一个 GUI,它将接受多个输入并通过多个函数运行它们。 我希望使用单选按钮面板在不同的图表之间切换,但我似乎无法让它工作。 这是我的代码示例。
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object
case 'button1'
status1 = str2double(get(handles.button1,'Value'));
if status1 == 1;
axes(handles.axes1)
grid on;
plot(x1,y1)
end
case 'button2'
status2 = str2double(get(handles.button2,'Value'));
if status2 == 1;
axes(handles.axes1)
grid on;
plot(x2,y2)
end
case 'button3'
status3 = str2double(get(handles.button3,'Value'));
if status3 ==1
plot(x3,y3)
end
otherwise
% Code for when there is no match.
end
I am trying to create a GUI that will take several inputs and run them through several functions. I wish to use a radio button panel to switch between different graphs, but i just cant seem to get it working. Here is a sample of my code.
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object
case 'button1'
status1 = str2double(get(handles.button1,'Value'));
if status1 == 1;
axes(handles.axes1)
grid on;
plot(x1,y1)
end
case 'button2'
status2 = str2double(get(handles.button2,'Value'));
if status2 == 1;
axes(handles.axes1)
grid on;
plot(x2,y2)
end
case 'button3'
status3 = str2double(get(handles.button3,'Value'));
if status3 ==1
plot(x3,y3)
end
otherwise
% Code for when there is no match.
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎正在尝试创建单选按钮面板 以类似于blinkdagger.com 上的示例教程。 具体来说,我相信您正在尝试创建 SelectionChangeFcn< /a> 定义单选按钮如何修改 GUI。 我建议如下:
首先,我建议您在创建 GUI 时绘制所有线条,然后将线条的“可见”属性调整为“开”或“关”取决于选择的按钮。 当您制作 GUI 时,您可以在代码中的某处添加这些线(在创建轴并将其放置在
handles
变量中之后):这将在同一轴上绘制三组线。 这些线最初是不可见的,每条绘制线的句柄都收集在向量变量
lineHandles
中。 上面的最后两行将线句柄添加到句柄结构中并更新 GUI 数据(hObject
应该是 GUI 图形窗口的句柄!)。现在,您可以对 SelectionChangeFcn 使用以下内容:
注意:如果您想更改绘制的三条线中的任何一条,只需设置其中一条线的“XData”和“YData”属性即可的线控柄。 例如,这将使用新的 x 和 y 数据更新第一条绘制线:
It appears that you are trying to create a radio button panel in a way similar to this example tutorial on blinkdagger.com. Specifically, I believe you are trying to create a SelectionChangeFcn to define how the radio buttons modify your GUI. I would suggest the following:
First, instead of replotting a line every time a radio button is selected, I would suggest that you plot all of your lines when you create your GUI and then adjust the 'Visible' property of the lines to either 'on' or 'off' depending on which button is selected. When you make your GUI, you can add these lines somewhere in your code (after the axes is created and placed in the
handles
variable):This will plot three sets of lines on the same axes. These lines are initially not visible, and handles to each plotted line are collected in a vector variable
lineHandles
. The last two lines above add the line handles to the handles structure and update the GUI data (hObject
should be a handle to the GUI figure window!).Now, you can use the following for your SelectionChangeFcn:
NOTE: If you ever want to change any of the three lines that are plotted, you can simply set the 'XData' and 'YData' properties of one of the line handles. As an example, this updates the first plotted line with new x and y data:
除非您有充分的理由这样做,否则我认为您应该将绘图代码放在每个单选按钮的回调中。
不需要做这么大的开关站。
此外,从按钮中出来的“值”已经是单选按钮的双精度值。 无需像您所做的那样对其进行转换。
Unless you have a good reason to do otherwise, I think you should put the plotting code inside the callback for each radio button.
No need to do this big switchyard.
Also, the 'value' that comes out of the button it is already a double for radio buttons. No need to convert it as you are doing.