Matlabstan Error Getting Stan Version

I have installed Matlabstan and I tried to run the ‘‘rats’’ example, and then Matlab returns the error information below:

Having a problem getting stan version.
This is likely a problem with Java running out of file descriptors
Trying again.
Trying again.
Trying again.
Trying again.
Trying again.
Trying again.
Giving up.
Error using cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set ‘UniformOutput’ to false.

Error in StanModel/stan_version (line 851)
ver = cellfun(@str2num,regexp(str{3},’.’,‘split’));

Error in StanModel (line 196)
ver = self.stan_version();

Error in stan (line 108)
model = StanModel();

Error in rats (line 20)
fit = stan(‘file’,‘rats.stan’,‘data’,rats_dat,‘verbose’,true);

I tried the solution suggested by @niklasb in Matlabstan - "Having a problem getting stan version." - #9 by mitzimorris that simply replacing the stan_version() part in StanModel.m with

function ver = stan_version(self)
ver = [2 29 1];
end

However it returns a new error:

rats
Error using StanModel/set.file (line 332)
File does not exist

Error in StanModel/set (line 275)
self.file = p.Results.file;

Error in StanModel/sampling (line 730)
self.set(varargin{:});

Error in stan (line 138)
fit = model.sampling(p.Unmatched);

Error in rats (line 20)
fit = stan(‘file’,‘rats.stan’,‘data’,rats_dat,‘verbose’,true);

I wonder if anybody can help me with this issue. I am using Matlab R2021a the cmdstan version is 2.29.1.

Update:

I have updated the cmdstan version to 2.29.2; I still used the solution above, and also I copied everything in the ‘Examples’ folder to the working directory and it looks like this:

image

Then I run the example ‘rats’ again but a new error occurs:

We have to compile the model first...
Error using processManager/start (line 366)
Java exception occurred:
java.io.IOException: Cannot run program "make" (in directory "C:\Users\cgxy2\Anaconda3\Library\bin\cmdstan"): CreateProcess error=2,
The system cannot find the file specified

	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

	at java.lang.Runtime.exec(Runtime.java:620)

	at java.lang.Runtime.exec(Runtime.java:450)

Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified

	at java.lang.ProcessImpl.create(Native Method)

	at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)

	at java.lang.ProcessImpl.start(ProcessImpl.java:137)

	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)

	... 2 more


Error in processManager/set.command (line 216)
            self.start();

Error in processManager (line 181)
         self.command = p.Results.command;

Error in StanModel/compile (line 897)
         p = processManager('id','compile',...

Error in StanModel/sampling (line 736)
            self.compile();

Error in stan (line 138)
      fit = model.sampling(p.Unmatched);

Error in rats (line 20)
fit = stan('file','rats.stan','data',rats_dat,'verbose',true);

this looks like a problem with you path or environment - you need to have Gnu-Make somewhere in your path. how did you install CmdStan?

the matlab Stan repo hasn’t been updated in 5 years - maybe @brian-lau or @jpiironen could advise?

Sorry, no clue. I stopped using Matlab several years ago, and haven’t used matlabstan since that. So I can’t really help unfortunately.

I installed cmdstan by using Anaconda commands

I’m not sure how the conda environment will interact with matlab. I think you will need to launch matlab from within the environment in order to use it this way

Except the compilation issue of the rats.stan I copied from the ‘Example’ folder, could anybody please help me with the issue of running rats.m? I first run it without typing the cmdstan version number in StanModel.m manually and it had such problem:

Having a problem getting stan version.
This is likely a problem with Java running out of file descriptors
Trying again.
Trying again.
Trying again.
Trying again.
Trying again.
Trying again.
Giving up.
Error using cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set ‘UniformOutput’ to false.

Error in StanModel/stan_version (line 851)
ver = cellfun(@str2num,regexp(str{3},’.’,‘split’));

Error in StanModel (line 196)
ver = self.stan_version();

Error in stan (line 108)
model = StanModel();

Error in rats (line 20)
fit = stan(‘file’,‘rats.stan’,‘data’,rats_dat,‘verbose’,true);

I then tried the solution suggested by @niklasb in Matlabstan - “Having a problem getting stan version.” - #9 by mitzimorris that simply replacing the stan_version() part in StanModel.m with

function ver = stan_version(self)
ver = [2 29 1];
end

And it returns

>> rats
Error using StanModel/set.file (line 333)
File does not exist

Error in StanModel/set (line 275)
               self.file = p.Results.file;

Error in StanModel/sampling (line 730)
         self.set(varargin{:});

Error in stan (line 138)
      fit = model.sampling(p.Unmatched);

Error in rats (line 20)
fit = stan('file','rats.stan','data',rats_dat,'verbose',true);

I don’t know why the stan function used in rats.m does not create a rats.stan file here.

I tried to launch Matlab from Anaconda Prompt but it still doesn’t work

Hello! I have the same problem. Any solution?