too many output arguments when running app

1 回表示 (過去 30 日間)
Fortino
Fortino 2022 年 9 月 2 日
コメント済み: Walter Roberson 2022 年 9 月 3 日
Hi there I am getting the too many output arguments when I hit the button, basically I am trying to use the switch to load two different data sets depending on which side it is (I got this part correct working by itself as well as when hitting the button), but when I introduced the dropdown menu, I want to select between two options but I am getting the error. The switch and button and plotting it works perfectly but when I tried the drop down it appears to not work and I cant figure out what the problem is, here is the code:
function ButtonPushed(app, event)
switch app.SchoolDropDown.Value
case'UCSD'
value = app.Switch.Value;
if strcmp(value,'Off')
load("UCSDWEATHER.mat")
plot(app.UIAxes,UCSDDAYS,UCSDHIGH,'r')
else
load("UCSDWEATHER.mat")
plot(app.UIAxes,UCSDDAYS,UCSDLOW,'g')
end
otherwise 'UCLA'
value = app.Switch.Value;
if strcmp(value,'Off')
load("UCLAWEATHER.mat")
plot(app.UIAxes,UCLADAYS,UCLAHIGH,'b')
else
load("UCSDWEATHER.mat")
plot(app.UIAxes,UCSDDAYS,UCSDLOW,'y')
end
end
  4 件のコメント
Image Analyst
Image Analyst 2022 年 9 月 3 日
編集済み: Image Analyst 2022 年 9 月 3 日
Can you attach your .mlapp file with the paperclip icon so we can try it? You said "The switch and button and plotting it works perfectly but when I tried the drop down it appears to not work". However only you gave us the code for the button, not for the drop down.
Make it easy for us to help you. If we don't have the .mlapp file, we're just guessing. 🤔
Fortino
Fortino 2022 年 9 月 3 日
編集済み: Fortino 2022 年 9 月 3 日
Hi, sorry for that, I just added it, this is a test I am doing so I can implement it once it works to my project, the reason I only attached the button code is because I want to use the drop down menu to chose a school for example, once I select the school I want to use the switch to load two different data sets for example one being in degree celsius and the other in farenheit and once I chose either of them use the button to plot it into the axis.
When I say that it works until I added the drop menu, I mean that it works like this:
function ButtonPushed(app, event)
value = app.Switch.Value;
if strcmp(value,'Off')
load("UCSDWEATHER.mat")
plot(app.UIAxes,UCSDDAYS,UCSDHIGH,'r')
else
load("UCSDWEATHER.mat")
plot(app.UIAxes,UCSDDAYS,UCSDLOW,'g')
end

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

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 9 月 3 日
You have
% Drop down opening function: DropDown
function SchoolDropDown(app, event)
end
so SchoolDropDown is a function -- one that returns no values.
Then you have the code
switch app.SchoolDropDown.Value
So you are invoking the function in a context that expects it to return an object to deference to get the Value component. But it doesn't return any values.
app.Button.ButtonPushedFcn = createCallbackFcn(app, @ButtonPushed, true);
You can see that you configured the button against the app.Button dropdown -- so it should be app.Button whose value you should be retrieving.
  2 件のコメント
Fortino
Fortino 2022 年 9 月 3 日
Oh okay, I see what is wrong but does that mean that I have to program them separately in order to make it work?
Walter Roberson
Walter Roberson 2022 年 9 月 3 日
What difference is there in your code between Dropdown and SchoolDropdown? Currently you create an object Dropdown and a function SchoolDropdown

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

カテゴリ

Help Center および File ExchangeCrystals についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by