Invalid syntax at <STRING>. Possibly a }, ), or ] is missing.
조회 수: 7(최근 30일)
I am trying to solve for reaction time variability using the ex-Gaussian method. Line 1 is causing problems; I typed in ('RT2') to access our data from excel, but I have received an error message saying Invalid syntax at STRING. Possibly a }, ), or ] is missing. I have tried to remove the quotation marks, but I need them in order to access my data. I have also tried removing the parentheses, but the function thinks it is a new line of code which it is not. I would like some fresh eyes to look at this and see what the problem could be. Any help is greatly appreciated, thanks! Please click on the screenshot.png attachment to see the function. Thanks again!
Ced 2016년 4월 12일
편집: Ced 2016년 4월 12일
I am confused on what you expect your function to do? That goes for pretty much all your function calls.
Let's have a look at e.g.
tau = std('RT2');
Unless you wrote your own std function, you are just passing a string and ask matlab to compute it's standard deviation? That doesn't really make sense. It's not a question of how you pass your string, the problem is that the standard deviation wants some numeric array and does not know what you want it to do with a string.
I think what you want is something like this:
function R = simple_egfit(datafile)
% 1. Load data
data = xlsread(datafile);
% 2. Process data
tau = std(data);
mu = mean(data)-skewness(data);
sig = sqrt(var(data)-tau.^2);
% 3. run optimization
pinit = [ mu sig tau ];
R = fminsearch(@(params) eglike(params,data),pinit);
Note 1: you will need to adjust the "Load data" part depending on what your file actually looks like.
Note 2: I would suggest passing the data as input argument instead of the file, i.e. transfer the loading part outside of that function into your script.