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
Dear Mr. Bengtsson, I worked on the code you sent. But, I dont think it is responding either. Kindly verify.> evaluate(matlab, "pwd=cd();");Sending expression on the Matlab server to be evaluated...: 'pwd=cd();' Received an 'MatlabException' reply (-1) from the Matlab server: 'Error: Expected a variable, function, or constant, found ")".' Error in list("evaluate(matlab, "pwd=cd();")" = <environment>, "evaluate.Matlab(matlab, "pwd=cd();")" = <environment>, : [2006-12-30 15:08:34] Exception: MatlabException: Error: Expected a variable, function, or constant, found ")". at throw(Exception(...)) at throw.default("MatlabException: ", lasterr) at throw("MatlabException: ", lasterr) at readResult.Matlab(this) at readResult(this) at evaluate.Matlab(matlab, "pwd=cd();") at evaluate(matlab, "pwd=cd();")> pwd <- getVariable(matlab, "pwd")$pwd;Retrieving variables from the Matlab server: 'pwd' Sending expression on the Matlab server to be evaluated...: 'variables = {'pwd'};' Received an 'OK' reply (0) from the Matlab server. Evaluated expression on the Matlab server with return code 0. Asks the Matlab server to send variables via the local file system... Error in readChar(con = con, nchars = nbrOfBytes) : invalid value for 'nchar'> print(pwd);Error in print(pwd) : object "pwd" not found> evaluate(matlab, "files=dir();")Sending expression on the Matlab server to be evaluated...: 'files=dir();' Error in readChar(con = con, nchars = nbrOfBytes) : invalid value for 'nchar' Kindly verify and let me know the solution. Regards, Bhanu Kalyan K Bhanu Kalyan K BTech CSE Final Year reach4kalyan@gmail.com Tel :+91-9885238228 __________________________________________________ [[alternative HTML version deleted]]
This is very odd, but maybe 'cd' is not a command on your Windows Matlab installation. I tried the same code on a Unix installation (I don't have access to Matlab for Windows but others have been using R.matlab there successfully). Find out what the command for getting the current directory in your Matlab version is and use that instead. You could also troubleshoot by this: 1. Start Matlab using Matlab$startServer(minimize=FALSE) 2. Setup the Matlab connection from R and close it with close(matlab). 3. Go to the Matlab windows and try the commands that failed for you when called from R. This will give you a hint. Remember, there is nothing magic going on. Think about the R Matlab connection as R is typing the Matlab commands for you; anything you can do in that Matlab windows which you did close(matlab) on you can do with evaluate(matlab, ...) - before closing it that is. /Henrik On 12/30/06, Bhanu Kalyan.K <kalyansikha at yahoo.com> wrote:> Dear Mr. Bengtsson, > > I worked on the code you sent. But, I dont think it is responding either. > Kindly verify. > > > evaluate(matlab, "pwd=cd();"); > > Sending expression on the Matlab server to be evaluated...: 'pwd=cd();' > Received an 'MatlabException' reply (-1) from the Matlab server: 'Error: > Expected a variable, function, or constant, found ")".' > Error in list("evaluate(matlab, "pwd=cd();")" = <environment>, > "evaluate.Matlab(matlab, "pwd=cd();")" = <environment>, : > > [2006-12-30 15:08:34] Exception: MatlabException: Error: Expected a > variable, function, or constant, found ")". > at throw(Exception(...)) > at throw.default("MatlabException: ", lasterr) > at throw("MatlabException: ", lasterr) > at readResult.Matlab(this) > at readResult(this) > at evaluate.Matlab(matlab, "pwd=cd();") > at evaluate(matlab, "pwd=cd();") > > > pwd <- getVariable(matlab, "pwd")$pwd; > > Retrieving variables from the Matlab server: 'pwd' > Sending expression on the Matlab server to be evaluated...: 'variables > {'pwd'};' > Received an 'OK' reply (0) from the Matlab server. > Evaluated expression on the Matlab server with return code 0. > Asks the Matlab server to send variables via the local file system... > Error in readChar(con = con, nchars = nbrOfBytes) : > invalid value for 'nchar' > > > print(pwd); > > Error in print(pwd) : object "pwd" not found > > > evaluate(matlab, "files=dir();") > > Sending expression on the Matlab server to be evaluated...: 'files=dir();' > Error in readChar(con = con, nchars = nbrOfBytes) : > invalid value for 'nchar' > > Kindly verify and let me know the solution. > > Regards, > Bhanu Kalyan K > > > > 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