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

1 Ansicht (letzte 30 Tage)
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 Kommentare
Walter Roberson
Walter Roberson am 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
Chin-Hao Chang am 29 Jul. 2019
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!

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by