Function error in app designer : too many output arguments

Hello,
I'm in trouble with a function I've coded this afternoon. It works perfectly on a classic matlab script, but when I try to use this function in the App Designer I get errors. In the code bellow, the function is "useless" but it should be operational. The purpose of this program is to fill in a tree node component from the first 3 columns of a table. The filling part is not visible because it is incomplete and anyway the program stops before.
  1. This is the function I've created (this function is ok, the problem come from when I'm calling it)
properties (Access = private)
arraySousElementUnique
end
methods (Access = private)
%%Purpose: this function allows to fill the tree selector by finding the values associated with a value in a table.
function sousElementUnique(app, tableau, colonneSource, valeurSource, colonneDestination)
j=1;
%Scrolls through the table, if an item matches the source value, then the function stores the associated value in an array.
for i=1:height(tableau)
if (cell2mat(tableau{i, colonneSource}) == valeurSource) && (convertCharsToStrings(cell2mat(tableau{i,colonneDestination})) ~= "")
app.arraySousElementUnique(j) = convertCharsToStrings(cell2mat(tableau{i,colonneDestination}));
j = j + 1;
end
end
%makes values unique
app.arraySousElementUnique = unique(app.arraySousElementUnique);
end
end
2. This is the startup function where I try to call the function I coded
function startupFcn(app)
app.arraySousElementUnique = strings;
tableauEvenManVoi = readtable('variable_evenement.xlsx');
%%can be replace by
%even = {'Paris';'Madrid';'Madrid';'Paris';'Madrid'};
%manche = {'Q1';'Q1';'Q1';'Q2';'Q3'};
%voiture = {'51';'51';'49';'43';'23'};
%tableauEvenManVoi = table(even,manche,voiture)
evenement = unique(tableauEvenManVoi{:,1});
for i= 1:length(evenement)
%%fill node
manche = sousElementUnique(app,tableauEvenManVoi,1,convertCharsToStrings(evenement{i}),2)
for j= 1:length(manche)
%%fill node
voiture = app.sousElementUnique(tableauEvenManVoi, 2, convertCharsToStrings(manche{j}), 3);
for k = 1:length(voiture)
%%fillnode
end
end
end
end
3. The error message
Error using appMatlabTest/sousElementUnique
Too many output arguments.
Error in appMatlabTest/startupFcn (line 48)
manche = sousElementUnique(app,tableauEvenManVoi,1,convertCharsToStrings(evenement{i}),2)
Error using matlab.apps.internal.GraphicsCallbackProxy/runCallbackFunction (line 23)
Error while evaluating GraphicsCallbackProxy CallbackFcn.

回答 (1 件)

Steven Lord
Steven Lord 2020 年 12 月 30 日

0 投票

The error message is correct. The private method is defined to return 0 output arguments.
function sousElementUnique(app, tableau, colonneSource, valeurSource, colonneDestination)
You are calling it and asking it to return 1 output argument.
manche = sousElementUnique(app,tableauEvenManVoi,1,convertCharsToStrings(evenement{i}),2)
You're calling the function with too many output arguments since 1 is greater than 0. Either change the definition of sousElementUnique so it returns an output argument or change the locations where you call it so those locations call sousElementUnique with 0 output arguments.

1 件のコメント

Robin Scarpellini
Robin Scarpellini 2020 年 12 月 30 日
Oh all right. I admit I struggled with a series of error messages and I lost track a bit. Thank you very much.

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

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

リリース

R2020b

質問済み:

2020 年 12 月 30 日

コメント済み:

2020 年 12 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by