Encode function not enough input arguments error in App Designer but works fine in MATLAB script

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

To help debug, add in the function:
disp(class(bag));
which encode(bag)
which -all encode
Hey there,
I'm not sure how I can do the debugging, for what confuses me is that the same function has different performances on MATLAB and App Designer.
What I'm suspecting now is App Designer might have interpreted encode as block encoder instead of document encoder. Is there the other way to solve this or is there another similar function I can apply?
You might suspect that, but if you were to post the output I requested, then we would *know* rather than just suspecting.
Hi Walter,
I finally figured out the problem. Using the function "load" results in struct-type output, which isn't recognizable by the function "encode". Hence instead of passing bag & mdl into the argument, use the code below instead:
newValidationData = preprocessText(app, app.UITable2.Data);
XNew = encode(bag.bag, newValidationData);
app.UITable3.Data = predict(mdl.mdl, XNew);
The correct data type will consequently be passed into the function. Thank you for taking your time Walter, I appreciate it!

Sign in to comment.

Answers (0)

Products

Release

R2019a

Asked:

on 26 Jul 2019

Commented:

on 29 Jul 2019

Community Treasure Hunt

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

Start Hunting!