Encode function not enough input arguments error in App Designer but works fine in MATLAB script
Show older comments
I was trying to write a GUI for text classification by app designer. I've also written a script (.m file) to do the basic functions testing.
In the script, everything worked out perfectly as I wanted. Part of the code is shown as below:
newValidationdata = preprocessText(validationData); %validationdata is a 80X1 string array; preprocessText is a function I've defined for text cleaning.
XNew = encode(bag, newValidationData); %bag is a bagOfWords variable
[labelsNew, score, cost] = predict(mdl, XNew); %mdl is the resulting model after training
I passed two arguments to the encode function and nothing went wrong. The encode function was executable in the command window.
In App Designer I created a classify button and its callback function is performing the same operation mentioned above in the code:
bag = load('bag.mat');
mdl = load('mdl.mat');
newValidationData = preprocessText(app, app.UITable2.Data);
XNew = encode(bag, newValidationData);
app.UITable3.Data = predict(mdl, XNew);
After running the app, however, it shows the message: "Error using encode (line 19) Not enough input arguments." How's that possible if the code works on MATLAB but not in App Designer?
I've tried to add "app" a the first argument of encode.
encode(app, bag, newValidationData);
As it turned out, a different message popped out: "Undefined function 'floor' for input arguments of type 'struct'. Error in encode (line 51) if (floor(n) ~= n) || (n<1)" How should I resolve this problem?
5 Comments
Walter Roberson
on 26 Jul 2019
To help debug, add in the function:
disp(class(bag));
which encode(bag)
which -all encode
Chin-Hao Chang
on 29 Jul 2019
Chin-Hao Chang
on 29 Jul 2019
Walter Roberson
on 29 Jul 2019
You might suspect that, but if you were to post the output I requested, then we would *know* rather than just suspecting.
Chin-Hao Chang
on 29 Jul 2019
Answers (0)
Categories
Find more on Design of Experiments (DOE) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!