GUI For循环按钮

时间:2012-03-17 21:15:14

标签: matlab user-interface button loops

我有多个频道,我想在GUI上显示他们的信息。 我想显示名称,长度,采样率等,并有一个按钮来绘制它或修改增益。

每个频道都是独立的,它并不总是相同数量的频道,因此我想为一个频道创建一个模式并显示它与频道一样多的时间,例如每个频道位于前一个频道的下方

它基本上是一个图形对象函数的循环,但我不知道最好的方法。

如果您有任何建议......

由于

1 个答案:

答案 0 :(得分:0)

你的问题是一般性的,所以根据细节,可能会有更多的解决方案。但是,一般的方法如下:

假设你有一个函数plotSingleChannel,它将通道数据和GUI上可用的位置作为输入,你可以在for循环中调用它,就像有通道一样。一个玩具的例子是,你需要调整它以满足你的需求(例如,可能打开多个数字来处理许多频道):

function plotManyChannels
fgui = figure;
numChannels = 5;
chData = rand (numChannels , 1000); % 5 random channels
chHeight = .8 * 1/numChannels; % occupy 80% of the available space, in order to leave some free inter-channel margins

for n = 1 : numChannels
    pos = [.05, 1 - n / numChannels, .9, chHeight];
    plotSingleChannel (chData(n,:), fgui, pos);
end
end

function plotSingleChannel (channelData, figHandle, guiPosition)
figure(figHandle)
buttonWidth = .1;
buttonPosition = [1-buttonWidth,guiPosition(2),buttonWidth,guiPosition(4)];
axHandle = axes ('position', guiPosition - [0 0 buttonWidth 0]);
plot(axHandle, channelData);
btnHandle = uicontrol('parent',figHandle,'style','pushbutton','string','push','units','normalized','position',buttonPosition);
end
相关问题