Invalid syntax at <STRING>. Possibly a }, ), or ] is missing.
6 views (last 30 days)
Show older comments
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!
Star Strider on 12 Apr 2016
‘I did use Ced's code ...’
No, you didn’t.
The first line of your function is:
function R = simple_egfit4(~)
that seems to have thrown an error (although we can’t see everything).
Then you had within your function:
data = xlsread('RT2');
Go back and use his code exactly as he wrote it. Then call your function as:
filename = 'RT2.xlsx'; % ... Or Whatever The Full Filename Is
R = simple_egfit(filename);
Then if it works (as I believe it will), Accept his Answer.
Ced on 12 Apr 2016
Edited: Ced on 12 Apr 2016
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.
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!