我将 Octave GNU 用于 GUI Excel 数据。我想问你们如何在另一个函数中调用已定义的参数。这是我的代码。
%%First Function = pushbutton_Callback
function pushbutton_Callback(hObject, eventdata, handles)
fileName = uigetfile('*.xlsx')%%excel data import
handles.fileName=fileName;
guidata(hObject, handles)
endfunction
%%Second Function = popupmenuX_Callback
function popupmenuX_Callback(hObject, eventdata, handles)
fileName = fileName @pushbutton_Callback;
printf ("in popupmenuX_Callback, calling pushbutton_Callback\n");
%%To nested function to prevent (because in Octave nested function is not accepted), I used subfunction as alternative%%
handles.fileName=fileName; %% This argument fileName I want to bring from first function
[numbers, colNames]=xlsread(fileName); %%read columns of excel data in first function
set(hObject,'string',colNames);
endfunction
如果我这样放置我的函数,总是会出现这些错误。
>> fileName = V8.xlsx
error: superclass calls can only occur in methods or constructors
error: called from
popupmenuX_Callback at line 61 column 10
所以我想做的是,我想将第一个函数(pushbutton_Callback)中定义的参数“fileName”带到第二个函数(popupX_callback)。但它不能在第二个函数中定义。我听说octave 中的嵌套函数可以用“foo”、“foobar”或“ex_top”、“ex_a”函数解析。但我无法解决“ex_”函数的问题。那么我是否必须使用“foo”、“foobar”函数将参数调用到其他函数中?
此致!
==================================================== ==========================
我用我的完整代码编辑了我的问题。(下面的完整代码)所以我想做的是,就像这个视频一样。但在视频中的 Matlab 中,可以使用 GUIDE 或应用程序设计器制作,但在 Octave 中没有这样的功能。所以作为一个八度初学者,我很难解决这个问题。
%%Versuch
%% Diagramm zeichen
%%============================================================================
close all
clear h
graphics_toolkit qt
pkg load io
%%Uicontrols
%%Graph
h.ax = axes ("position", [0.3 0.25 0.6 0.5]);
%%Title
h.plot_title_label = uicontrol ("style", "text",
"units", "normalized",
"string", "Versuchsergebnis",
"horizontalalignment", "left",
"position", [0.03 0.9 0.25 0.08]);
%% Design for excel data import
h.print_pushbutton = uicontrol ("style", "pushbutton",
"units", "normalized",
"string", "Excel Datei mitbringen",
"callback", @pushbutton_Callback,
"position", [0.03 0.8 0.3 0.09]);
%% Drawing axis
h.popupmenuX = uicontrol("Style","popupmenu",
"units", "normalized",
"string","X Axis",...
"callback", @popupmenuX_Callback,
"Position",[0.7 0.04 0.2 0.05]);
h.popupmenuY = uicontrol("Style","popupmenu",
"units", "normalized",
"string","Y Axis",
"callback",@popupmenuY_Callback,
"Position",[0.03 0.5 0.2 0.05]);
%%=============================================================================
%% Functions
%%=============================================================================
%% 1. Excel Data import
function pushbutton_Callback(hObject, eventdata, handles)
fileName = uigetfile('*.xlsx')%%excel data import
handles.fileName = fileName;
guidata(hObject, handles)
endfunction
%% 2. X Axis Information from excel data import
function popupmenuX_Callback(hObject, eventdata, handles)
fileName = pushbutton_Callback(hObject, eventdata, handles)
%%This code fileName causes error, that 'handles' is not defined.%%
handles.fileName = fileName; %% This argument fileName I want to bring from first function
[numbers, colNames] = xlsread(fileName); %%read columns of excel data in first function
set(hObject,'string',colNames);
endfunction
%% 3. Y Axis Information from excel data import
function popupmenuY_Callback(hObject, eventdata, handles)
filename = pushbutton_Callback(hObject, eventdata, handles)
handles.fileName = fileName;
[numbers, colNames] = xlsread(fileName);
set(hObject,'string',colNames);
endfunction
%%%% Plot the graph
a = xlsread (fileName);
xColNum = get(popupmenuX_Callback,'value');
yColNum = get(popupmenuY_Callback,'value');
fileName = handles.fileName;
x = a(:,xColNum);
y = a(:,yColNum);
h.ax = plot(x,y);