Invalid syntax at <STRING>. Possibly a }, ), or ] is missing.
조회 수: 5 (최근 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
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
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!