Octave 如何创建uitab或uitab组

Octave 如何创建uitab或uitab组,octave,Octave,我想用八度音阶运行一些Matlab代码。 它调用uitabgroup() 我已经寻找了一种八度音阶的方法来创建标签,但是没有用 我有fltk gnuplot和qt图形工具包可用 有人能帮忙吗 谢谢出于兴趣,我试了一下。这里我展示了一个特定的示例,说明如何使用uitabgroup和uitab将简单代码转换为倍频程。这决不是一个通用的解决方案,但是如果您研究代码几分钟,就应该清楚地知道如何使其适应您自己的问题 主要思想是编写自己的uitabgroup和uitab函数,让它们在同一位置创建“按钮”而不

我想用八度音阶运行一些Matlab代码。 它调用uitabgroup() 我已经寻找了一种八度音阶的方法来创建标签,但是没有用 我有fltk gnuplot和qt图形工具包可用

有人能帮忙吗


谢谢

出于兴趣,我试了一下。这里我展示了一个特定的示例,说明如何使用
uitabgroup
uitab
将简单代码转换为倍频程。这决不是一个通用的解决方案,但是如果您研究代码几分钟,就应该清楚地知道如何使其适应您自己的问题

主要思想是编写自己的
uitabgroup
uitab
函数,让它们在同一位置创建“按钮”而不是“选项卡标签”和“uipanels”,作为选项卡内容。按下每个按钮可使一个uipanel可见并隐藏所有其他uipanel

下面是比较结果:

matlab代码:

% in 'uitabs_matlab_demo.m'

clf
f = figure( 1 );   set( f, 'position', [500, 500, 500, 500 ] );

tabgp = uitabgroup( f, 'position', [.05, .05, .9, .9] );

tab1 = uitab( tabgp, 'title','Data' );
tab2 = uitab( tabgp, 'title','Plot' );

ax = axes( tab2, 'position', [ 0.1, 0.1, 0.80, 0.80 ] );
p  = plot( ax, 1:9 );

axis( [0, 10, 0, 10 ] );
title( 'Dynamic Plot', 'fontsize', 10, 'fontweight', 'normal' );

u1_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 1,   Y = ', 'units', 'normalized', 'position', [0.05, 0.90, 0.20, 0.05] );
u2_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 2,   Y = ', 'units', 'normalized', 'position', [0.05, 0.80, 0.20, 0.05] );
u3_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 3,   Y = ', 'units', 'normalized', 'position', [0.05, 0.70, 0.20, 0.05] );
u4_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 4,   Y = ', 'units', 'normalized', 'position', [0.05, 0.60, 0.20, 0.05] );
u5_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 5,   Y = ', 'units', 'normalized', 'position', [0.05, 0.50, 0.20, 0.05] );
u6_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 6,   Y = ', 'units', 'normalized', 'position', [0.05, 0.40, 0.20, 0.05] );
u7_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 7,   Y = ', 'units', 'normalized', 'position', [0.05, 0.30, 0.20, 0.05] );
u8_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 8,   Y = ', 'units', 'normalized', 'position', [0.05, 0.20, 0.20, 0.05] );
u9_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 9,   Y = ', 'units', 'normalized', 'position', [0.05, 0.10, 0.20, 0.05] );

u1_y   = uicontrol( tab1, 'style', 'edit', 'String', '1', 'units', 'normalized', 'position', [0.25, 0.90, 0.20, 0.05], 'callback', {@y_callback, p, 1} );
u2_y   = uicontrol( tab1, 'style', 'edit', 'String', '2', 'units', 'normalized', 'position', [0.25, 0.80, 0.20, 0.05], 'callback', {@y_callback, p, 2} );
u3_y   = uicontrol( tab1, 'style', 'edit', 'String', '3', 'units', 'normalized', 'position', [0.25, 0.70, 0.20, 0.05], 'callback', {@y_callback, p, 3} );
u4_y   = uicontrol( tab1, 'style', 'edit', 'String', '4', 'units', 'normalized', 'position', [0.25, 0.60, 0.20, 0.05], 'callback', {@y_callback, p, 4} );
u5_y   = uicontrol( tab1, 'style', 'edit', 'String', '5', 'units', 'normalized', 'position', [0.25, 0.50, 0.20, 0.05], 'callback', {@y_callback, p, 5} );
u6_y   = uicontrol( tab1, 'style', 'edit', 'String', '6', 'units', 'normalized', 'position', [0.25, 0.40, 0.20, 0.05], 'callback', {@y_callback, p, 6} );
u7_y   = uicontrol( tab1, 'style', 'edit', 'String', '7', 'units', 'normalized', 'position', [0.25, 0.30, 0.20, 0.05], 'callback', {@y_callback, p, 7} );
u8_y   = uicontrol( tab1, 'style', 'edit', 'String', '8', 'units', 'normalized', 'position', [0.25, 0.20, 0.20, 0.05], 'callback', {@y_callback, p, 8} );
u9_y   = uicontrol( tab1, 'style', 'edit', 'String', '9', 'units', 'normalized', 'position', [0.25, 0.10, 0.20, 0.05], 'callback', {@y_callback, p, 9} );

% In matlab, in-line functions need to be defined at the END of a script
function y_callback( Handle, Event, PlotHandle, XVal )
   YData = get( PlotHandle, 'ydata' );
   YData( XVal ) = str2num( get( Handle, 'string' ) );
   set( PlotHandle, 'ydata', YData );
end
等效倍频程代码:

% in 'uitabs_octave_demo.m'

% Starting an m-file with an instruction as opposed to a 'function' keyword, 
%   interprets the m-file as a script, as opposed to a function definition. 
1;

% In octave, in-line functions need to be defined 'before' their use, as opposed
%   to matlab which demands them at the 'end' of a script.

function y_callback( Handle, Event, PlotHandle, XVal )
   YData = get( PlotHandle, 'ydata' );
   YData( XVal ) = str2num( get( Handle, 'string' ) );
   set( PlotHandle, 'ydata', YData );
end

% This is the "extra" bit we provide; since octave does not currently implement the
%   'uitabgroup' and 'uitab' functions, we provide our own definitions for them here

function Handle = uitabgroup( FigHandle, PosOpt, PosVal )
   Handle = uipanel( FigHandle, PosOpt, PosVal);
   setappdata( Handle, 'tabs_buttons', {} );
   setappdata( Handle, 'tabs_contents', {} );
end

function on_tab_select( Handle, Event, TabGroupHandle, TabContents )
   Tabs_contents = getappdata( TabGroupHandle, 'tabs_contents' )
   for i=1:length(Tabs_contents); set(Tabs_contents{i}, 'visible', 'off'); end
   set( TabContents, 'visible', 'on' );
end

function TabContents = uitab( TabGroupHandle, TitleOpt, TitleVal )
   Tabs_buttons  = getappdata( TabGroupHandle, 'tabs_buttons'  );
   Tabs_contents = getappdata( TabGroupHandle, 'tabs_contents' );
   TabContents = uipanel( TabGroupHandle, 'units', 'normalized', 'position', [ 0, 0, 1, 0.95 ] );
   TabButton   = uicontrol( TabGroupHandle, 'style', 'pushbutton' ,'string', TitleVal, 'units', 'normalized', 'position', [ length(Tabs_buttons) * 0.1, 0.95, 0.1, 0.05 ], 'callback', {@on_tab_select, TabGroupHandle, TabContents } );
   Tabs_buttons{end+1}  = TabButton;
   Tabs_contents{end+1} = TabContents;
   setappdata( TabGroupHandle, 'tabs_buttons' , Tabs_buttons );
   setappdata( TabGroupHandle, 'tabs_contents', Tabs_contents );
end

% Rest of script as before
clf
f = figure( 1 );   set( f, 'position', [500, 500, 500, 500 ] );

tabgp = uitabgroup( f, 'position', [.05, .05, .9, .9] );

tab1 = uitab( tabgp, 'title','Data' );
tab2 = uitab( tabgp, 'title','Plot' );

ax = axes( tab2, 'position', [ 0.1, 0.1, 0.80, 0.80 ] );
p  = plot( ax, 1:9 );

axis( [0, 10, 0, 10 ] );
title( 'Dynamic Plot', 'fontsize', 10, 'fontweight', 'normal' );

u1_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 1,   Y = ', 'units', 'normalized', 'position', [0.05, 0.90, 0.20, 0.05] );
u2_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 2,   Y = ', 'units', 'normalized', 'position', [0.05, 0.80, 0.20, 0.05] );
u3_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 3,   Y = ', 'units', 'normalized', 'position', [0.05, 0.70, 0.20, 0.05] );
u4_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 4,   Y = ', 'units', 'normalized', 'position', [0.05, 0.60, 0.20, 0.05] );
u5_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 5,   Y = ', 'units', 'normalized', 'position', [0.05, 0.50, 0.20, 0.05] );
u6_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 6,   Y = ', 'units', 'normalized', 'position', [0.05, 0.40, 0.20, 0.05] );
u7_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 7,   Y = ', 'units', 'normalized', 'position', [0.05, 0.30, 0.20, 0.05] );
u8_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 8,   Y = ', 'units', 'normalized', 'position', [0.05, 0.20, 0.20, 0.05] );
u9_x   = uicontrol( tab1, 'style', 'text', 'string', 'X = 9,   Y = ', 'units', 'normalized', 'position', [0.05, 0.10, 0.20, 0.05] );

u1_y   = uicontrol( tab1, 'style', 'edit', 'String', '1', 'units', 'normalized', 'position', [0.25, 0.90, 0.20, 0.05], 'callback', {@y_callback, p, 1}, 'backgroundcolor', 'w' );
u2_y   = uicontrol( tab1, 'style', 'edit', 'String', '2', 'units', 'normalized', 'position', [0.25, 0.80, 0.20, 0.05], 'callback', {@y_callback, p, 2}, 'backgroundcolor', 'w' );
u3_y   = uicontrol( tab1, 'style', 'edit', 'String', '3', 'units', 'normalized', 'position', [0.25, 0.70, 0.20, 0.05], 'callback', {@y_callback, p, 3}, 'backgroundcolor', 'w' );
u4_y   = uicontrol( tab1, 'style', 'edit', 'String', '4', 'units', 'normalized', 'position', [0.25, 0.60, 0.20, 0.05], 'callback', {@y_callback, p, 4}, 'backgroundcolor', 'w' );
u5_y   = uicontrol( tab1, 'style', 'edit', 'String', '5', 'units', 'normalized', 'position', [0.25, 0.50, 0.20, 0.05], 'callback', {@y_callback, p, 5}, 'backgroundcolor', 'w' );
u6_y   = uicontrol( tab1, 'style', 'edit', 'String', '6', 'units', 'normalized', 'position', [0.25, 0.40, 0.20, 0.05], 'callback', {@y_callback, p, 6}, 'backgroundcolor', 'w' );
u7_y   = uicontrol( tab1, 'style', 'edit', 'String', '7', 'units', 'normalized', 'position', [0.25, 0.30, 0.20, 0.05], 'callback', {@y_callback, p, 7}, 'backgroundcolor', 'w' );
u8_y   = uicontrol( tab1, 'style', 'edit', 'String', '8', 'units', 'normalized', 'position', [0.25, 0.20, 0.20, 0.05], 'callback', {@y_callback, p, 8}, 'backgroundcolor', 'w' );
u9_y   = uicontrol( tab1, 'style', 'edit', 'String', '9', 'units', 'normalized', 'position', [0.25, 0.10, 0.20, 0.05], 'callback', {@y_callback, p, 9}, 'backgroundcolor', 'w' );

目前似乎不支持此命令,但原则上用现有命令模拟其功能应该很简单,因为选项卡所做的是在按下“标题”按钮时有效地隐藏/取消隐藏位于相同坐标中的轴。如果您愿意,您可以使用uitoolbar或按钮组等。如果您确实愿意,您可以使其看起来完全像选项卡式界面。另一方面,如果你要问的是,是否有一个神奇的命令可以用最少的编辑来转换你的matlab UITABGOUP代码,那么可能没有。话虽如此,我认为可能有一个漂亮的替换涉及UITABGOUP->UIButtongGroup和uitab->uicontrol,这将起作用。。。