[R] Evaluating Entire Matlab code at a time

Henrik Bengtsson hb at stat.berkeley.edu
Sat Dec 30 08:47:58 CET 2006


Hi.

On 12/30/06, Bhanu Kalyan.K <kalyansikha at yahoo.com> wrote:
> Dear Mr.Bengtsson,
>
> The steps you have suggested are working for single lines of matlab
> statements. But, as i mentioned earlier, If i want to see the output of an
> entire matlab code (say swissroll.m) then you suggested me to do
> res <- evaluate(matlab, "swissroll").
> When i did this the output looks something like:
>
> > res <- evaluate(matlab, "swissroll")
>
>  Sending expression on the Matlab server to be evaluated...: 'swissroll'
>  Received an 'MatlabException' reply (-1) from the Matlab server: 'Undefined
> function or variable 'lle'.'
>  Error in list("evaluate(matlab, "swissroll")" = <environment>,
> "evaluate.Matlab(matlab, "swissroll")" = <environment>,  :
>
>  [2006-12-30 11:58:32] Exception: MatlabException: Undefined function or
> variable 'lle'.
>    at throw(Exception(...))
>    at throw.default("MatlabException: ", lasterr)
>    at throw("MatlabException: ", lasterr)
>    at readResult.Matlab(this)
>    at readResult(this)
>    at evaluate.Matlab(matlab, "swissroll")
>    at evaluate(matlab, "swissroll")
>
> // Here another matlab window titled "Figure no.1" (corresponding to the
> actual matlab output of swissroll.m) opened, but the window is blank. No
> output is being displayed. However,  when i used the same command for
> another matlab code, kMeansCluster.m, the warnings/Exceptions generated are
> similar to that os swissroll.m. Here is the output:
>
> > res <- evaluate(matlab, "kMeansCluster;")
>
> Sending expression on the Matlab server to be evaluated...: 'kMeansCluster;'
> Received an 'MatlabException' reply (-1) from the Matlab server: 'Undefined
> function or variable 'kMeansCluster'.'
> Error in list("evaluate(matlab, "kMeansCluster;")" = <environment>,
> "evaluate.Matlab(matlab, "kMeansCluster;")" = <environment>,  :
>
> [2006-12-30 11:56:34] Exception: MatlabException: Undefined function or
> variable 'kMeansCluster'.
>   at throw(Exception(...))
>   at throw.default("MatlabException: ", lasterr)
>   at throw("MatlabException: ", lasterr)
>   at readResult.Matlab(this)
>   at readResult(this)
>   at evaluate.Matlab(matlab, "kMeansCluster;")
>   at evaluate(matlab, "kMeansCluster;")
>
> The warnings generated are almost similar for those two different matlab
> codes. So i feel that the problem lies with the R and not the code. What do
> u suggest? how to deal with this?

To me this looks like Matlab can't find those commands, and then it
has nothing to with R. Make sure your Matlab scripts are available in
the Matlab path or in the working directory of Matlab.  You check the
working directory of Matlab with:

 evaluate(matlab, "pwd=cd();");
 pwd <- getVariable(matlab, "pwd")$pwd;
 print(pwd);

Check to see if your scripts are in the working directory:

 evaluate(matlab, "files=dir();")
 files <- getVariable(matlab, "files")$files
 unlist(files["name",,])

If not, you have to update your Matlab path or change the working directory.

Hope this helps

Henrik

>
>
>
>
> Bhanu Kalyan K
> BTech CSE Final Year
> reach4kalyan at gmail.com
> Tel :+91-9885238228
>
>  __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com



More information about the R-help mailing list