"Too many input arguments" error on function within GUI code

Hey! I am writing a GUI that takes in the data from an excel file and then plots in and fits a curve to the data to extract some characteristics of the curve. The code that I have written to build the GUI works fine, but when I try to get the callbacks for the uicontrols to work, I get an error. Here is the code that I am using:
rhUpload = uicontrol(...
'Style', 'pushbutton',...
'String', 'Upload Data',...
'Parent', rhMainFigure,...
'Units', 'normalized',...
'Callback', @rhImport,...
'Position', [0.7 0.25 0.2 0.03],...
'FontSize', 11);
is the code that creates the UI pushbutton
function rhData = rhImport
[file,path]=uigetfile;
rhData = xlsread(fullfile(path,file));
is the code that executes when the pushbutton is pressed. However, when I press the button, I get the following error:
Error using RheologyGUI>rhImport
Too many input arguments.
Error while evaluating uicontrol Callback
Interestingly, I took the function code and created a separate m-file for just that function, and when I execute it, it works fine. Do you know what may be causing this error? Thanks!

 採用された回答

Amit
Amit 2014 年 1 月 11 日

0 投票

Try rhImport(hObject,eventdata) instead of just rhImport.

2 件のコメント

Walter Roberson
Walter Roberson 2014 年 1 月 11 日
Right. Graphics callbacks are automatically passed two arguments.
CS MATLAB
CS MATLAB 2016 年 11 月 30 日
Thank you Amit

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

質問済み:

2014 年 1 月 10 日

コメント済み:

2016 年 11 月 30 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by