0

我正在努力使用 Octave GNU 制作用于绘制 Excel 数据的 GUI。 是我的最后一个问题。我想将弹出菜单中的字符串插入到每个 x 轴和 y 轴 Label 以及 Title 中。喜欢这张照片在此处输入图像描述

对于这段代码,我使用了这个(仅用于标题和 x 轴)。

      title     = get (hObject, 'string')
      set(get(h1, 'title'), 'string', title ) 
      
      xstring   = get (XAxisMenu, 'string')
      set(get(h1, 'xlabel'), 'string', xstring ) 

但是我看不到我的轴名称,我想知道如果我在弹出菜单中选择另一个类别,轴标签会如何变化。我的完整代码如下所示。

 clear all
 clc
 pkg load io

% Create the Gui Window which will hold all controls and relevant data.
  GuiWindow = figure()



% Static text element used as a title
  uicontrol ("style", "text", "units", "normalized", "string", "GUI",'ForegroundColor','w','BackgroundColor',[0 0.4470 0.7410],'Fontweight','bold', "horizontalalignment", "center", "position", [0.03 0.9 0.35 0.08] );
                                    
% A button for importing (excel) data
  uicontrol ("style", "pushbutton", "units", "normalized", "string", "Bring Excel Data", "callback", { @pushbutton_Callback, GuiWindow }, "position", [0.03 0.8 0.35 0.09], 'tag', 'button' );

% Popupmenus for selecting appropriate X and Y axis to display in plots
  uicontrol("Style","popupmenu", "units", "normalized", "string","X Axis", "callback", { @popupmenuX_Callback, GuiWindow }, "Position",[0.7 0.04 0.2 0.05], 'tag', 'XAxisMenu' );
  uicontrol("Style","popupmenu", "units", "normalized", "string","Y Axis", "callback", { @popupmenuY_Callback, GuiWindow }, "Position",[0.03 0.5 0.2 0.05], 'tag', 'YAxisMenu' );

  %%=============================================================================                              
  %% Functions (preferably placed in their own files!)
  %%=============================================================================

  function pushbutton_Callback(hObject, eventdata, GuiWindow)

    % Read in data from file, graphically selected by user
      fileName      = uigetfile('*.xlsx');
      [num,txt,raw] = xlsread(fileName);
      header        = raw(1,:);
      Data          = xlsread(fileName);
    % Show fileName
      button   = findobj('tag', 'button');
      set( button, 'string', fileName)
    % Populate the menu items for the X and Y Axis from the csv header
      XAxisMenu = findobj( 'tag', 'XAxisMenu' );
      set( XAxisMenu, 'string', header );

      YAxisMenu = findobj( 'tag', 'YAxisMenu' );
      set( YAxisMenu, 'string', header );

    % Also store headers and data as GuiWindow app data, in case we need them again later.
      setappdata( GuiWindow, 'header', header );
      setappdata( GuiWindow, 'Data'  , Data   );

    % Plot a preliminary plot in the plot area
      XData = Data(:, 1);
      YData = Data(:, 1);
    % An 'axes' object for displaying plots in the Gui Window
      h1 = axes ("position", [0.3 0.25 0.6 0.5], 'tag', 'plotarea' );
    
    % Axis Name  
      title     = get (hObject, 'string')
      set(get(h1, 'title'), 'string', title ) 
      
      xstring   = get (XAxisMenu, 'string')
      set(get(h1, 'xlabel'), 'string', xstring ) 
      
      plot( XData, YData, 'tag', 'plotobject' );          
  endfunction

  %% 2. X Axis Information from excel data import
  function popupmenuX_Callback( hObject, eventdata, GuiWindow )
      Axes      = findobj( 'tag', 'plotarea' );
      Selection = get( hObject, 'value' );
      XData     = [ getappdata( GuiWindow, 'Data' )( :, Selection ) ];
      PlotObj   = findobj( 'tag', 'plotobject' );
      set( PlotObj, 'xdata', XData )
  endfunction

  %% 3. Y Axis Information from excel data import
  function popupmenuY_Callback( hObject, eventdata, GuiWindow )
      Axes      = findobj( 'tag', 'plotarea' );
      Selection = get( hObject, 'value' );
      YData     = [ getappdata( GuiWindow, 'Data' )( :, Selection ) ];
      PlotObj   = findobj( 'tag', 'plotobject' );
      set( PlotObj, 'ydata', YData )
  endfunction

如果有人知道答案,我将不胜感激。感谢您阅读我的问题。

4

0 回答 0