Passing Data to Stan with MatlabStan

Hey everyone,

I have written and compiled my first Stan program and am working through the troubleshooting steps to get it up and running. The problem I’m running into is how to pass the data along from MATLAB. The data takes the form of a structural variable having a real value for the number of participants and a vector for the number of trials per participant, as well as a cell per participant with the matrix of their responses and a cell per participant of the stimuli they were presented. I will include the data block below. This is what the structural variable in Matlab looks like:


The error I receive is:

Operator ‘>’ is not supported for operands of type ‘cell’.

Error in mstan.rdump (line 22)
if any(data{i}(:) > intmax(‘int32’))

Error in StanModel/ (line 701)

Error in StanModel/set (line 298) =;

Error in StanModel/sampling (line 730)

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

data {

	int ns;													//number of subjects
	array[ns] int nt; 											//number of trials
	array[ns] matrix[4,nt[ns]] resps;									//responses
	array[ns] vector[nt[ns]] oris;										//orientations

Operating System: macOS Ventura 13.6
Interface Version: MatlabStan-

So I’m just looking for advice on the best way to format the data to hand it from Matlab to MatlabStan (including edits to the way the data is declared in the .stan file if necessary)



Unfortunately, MatlabStan isn’t actively maintained and doesn’t support the more recent data type introduced in Stan. I think the easiest for you would be to export the data manually and then use a Python* or R interface to stan.

*Python has some function to read directly Matlab mat file ( — SciPy v1.11.2 Manual)

Thanks! There is a good chance we will be porting over to Python in the near future, though I am not familiar with the language yet myself. This might be as good an excuse as any to finally start learning it