MATLAB Answers

0

Wrong function interpretation on App Designer

Asked by Chin-Hao Chang on 29 Jul 2019
Latest activity Answered by Steven Lord
on 20 Aug 2019
I tried to use the function "encode" in order to create matrix of n-gram counts.
newValidationdata = preprocessText(app, app.UITable2.Data);
XNew = encode(app.bag, newValidationData);
preprocessText is the function I've defined for text cleaning in text classification and its class of output is tokenizedDocuments, whereas app.bag is the bag of words model I've loaded into App Designer.
However, after compiling the error message "Not enough input arguments" popped out. I typed
open('encode.m')
and realized the compiler have interpreted encode function as block encoder, which requires 4 input arguments, instead of document encoder:
encode(msg,n,k)
What really confused me was even the function suggestions (the text that appears automatically below as one is typing) displayed what I wanted but never compiled the right way:
encode(bag,words,options)
As a whole, the document encoder worked fine on MATLAB Command Window but unfortunately not on App Designer. How can I fix this problem?

  1 Comment

That command is the wrong one to figure out which encode is being used. You need
which encode(app.bag, newValidationData)

Sign in to comment.

2 Answers

Answer by Subhadeep Koley on 20 Aug 2019

It is difficult to debug without the actual code, but you can temporarily remove the Communications Toolbox from MATLAB’s current path
Go to the Home tab, click Set Path, click the folder of the Communications Toolbox, and click Remove.
This does not delete the toolbox, but temporarily removes it from the current search path so that the functions in the toolbox doesn’t get executed anymore.
Later you can again add Communications Toolbox in the search path if necesserry.

  0 Comments

Sign in to comment.


Answer by Steven Lord
on 20 Aug 2019

You've encountered one of the problem listed in the Limitation section of the MATLAB Compiler documentation. You wrote:
whereas app.bag is the bag of words model I've loaded into App Designer.
From that documentation page:
"Dependent functions can also be hidden from the dependency analyzer in .mat files that are loaded by compiled applications. Use the mcc -a argument or the %#function pragma to identify .mat file classes or functions that are supported by the load command."
The dependency analysis MATLAB Compiler performs to determine what needs to be included in your application doesn't know that it needs to package the constructor and methods for the class object included in your MAT-file. Use the -a argument or the %#function pragma to tell it to include the bagOfWords constructor file (you can find this using which -all bagOfWords) which also includes the code for the encode method of that class.

  0 Comments

Sign in to comment.