Invalid syntax at <STRING>. Possibly a }, ), or ] is missing.

6 次查看(过去 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!
  5 个评论
Audreyana Jagger
Audreyana Jagger 2016-4-12
Hi Stephen,
I did use Ced's code, however another error message came up when I typed it into Matlab. I attached a screenshot of the message.
Thanks!
Star Strider
Star Strider 2016-4-12
‘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.

请先登录,再进行评论。

回答(1 个)

Ced
Ced 2016-4-12
编辑:Ced 2016-4-12
Hi
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);
end
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.
Cheers
  1 个评论
Audreyana Jagger
Audreyana Jagger 2016-4-12
Hello,
Thank you so much for your response, it is very helpful. To answer your question, we are trying to solve for the parameters mu, sig, and tau where mu is the mean, sig is the standard deviation, and tau is the mean of the exponential component.
Thanks!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by