# Parse error?

13 messages
Open this post in threaded view
|

## Parse error?

 Hi everyone, This is a bit of a long winded question: I am having problems with my code. I can't seem to get by it. Basically I am wanting to read in a file, do some analysis on it and then have a plot output. The piece of code below first reads in the file, splits the file into vectors and then the analysis. The function aver calculates the running mean of the data which, has many peaks. The idea is to find the points in the data set that just cross the running mean. I then want to fit a curve to the peak and find the maximum. This is essentially a peak finiding program. function gn = groupindcnt(filename); f = dlmread(filename); lambda = f(2:end,1); power = f(2:end,2:21); runmean = aver(lambda, power); %This for loop will loop over all the currents/columns in power for crnt = 1:1:20   data = power(:,crnt);   sign = 1;   cross = zeros(1000,1);   n = 1;     %This bit is finding the data points just above and below the running mean.   %and places a 1 in the vector cross.   for i = 1:1:9000     if (sign*(data(i+499)-runmean(i,crnt)) > 0)         sign = -1*sign;     cross(i) = 1;     n = n + 1;     end   end     %This bit is to remove the false crossing points, peaks are typically 30 data   %points wide.   for j = 1:1:length(cross)     if (cross(j)==1)       cross(j+1) = 0;           cross(j+2) = 0;           cross(j+3) = 0;           cross(j+4) = 0;           cross(j+5) = 0;           cross(j+6) = 0;           cross(j) = j;     end   end     %removing zeros from cross   cross(cross==0)=[];   data_cp = data(cross+499,:);   lambda_cp = lambda(cross+499);     %This is the bit I am having problems with, it runs through all of the crossing points   %and calculates if between two crossing points there is a maximum (the if statement).   for k = 2:1:length(cross)-1     cp = (499+ cross(k) + round((cross(k+1) - cross(k))/2));         ll = data((499 + cross(k)));         hl = data((499 + cross(k+1)));         ml = data(cp);                 if (ml > ((hl+ll)/2)                %ANYTHING ADDED IN HERE RETURNS PARSE ERROR                %This is where I want to do the curve fitting                   end                           end   end end This may be a bit hard to understand; it is dificult reading other peoples code I know! Basically anything I put in the IF statement causes a 'parse' error. Any suggestions? Cheers Martin Still learning everyday.
Open this post in threaded view
|

## Re: Parse error?

 On Thu, Aug 12, 2010 at 12:23 PM, dirac <[hidden email]> wrote: > > Hi everyone, > > This is a bit of a long winded question: I am having problems with my code. > I can't seem to get by it. Basically I am wanting to read in a file, do some > analysis on it and then have a plot output. > > The piece of code below first reads in the file, splits the file into > vectors and then the analysis. The function aver calculates the running mean > of the data which, has many peaks. The idea is to find the points in the > data set that just cross the running mean. I then want to fit a curve to the > peak and find the maximum. This is essentially a peak finiding program. > > > function gn = groupindcnt(filename); > > > f = dlmread(filename); > lambda = f(2:end,1); > power = f(2:end,2:21); > runmean = aver(lambda, power); > > %This for loop will loop over all the currents/columns in power > for crnt = 1:1:20 >  data = power(:,crnt); >  sign = 1; >  cross = zeros(1000,1); >  n = 1; > > >  %This bit is finding the data points just above and below the running > mean. >  %and places a 1 in the vector cross. >  for i = 1:1:9000 >    if (sign*(data(i+499)-runmean(i,crnt)) > 0) >        sign = -1*sign; >    cross(i) = 1; >    n = n + 1; >    end >  end > >  %This bit is to remove the false crossing points, peaks are typically 30 > data >  %points wide. >  for j = 1:1:length(cross) >    if (cross(j)==1) >      cross(j+1) = 0; >          cross(j+2) = 0; >          cross(j+3) = 0; >          cross(j+4) = 0; >          cross(j+5) = 0; >          cross(j+6) = 0; >          cross(j) = j; >    end >  end > >  %removing zeros from cross >  cross(cross==0)=[]; >  data_cp = data(cross+499,:); >  lambda_cp = lambda(cross+499); > > > >  %This is the bit I am having problems with, it runs through all of the > crossing points >  %and calculates if between two crossing points there is a maximum (the if > statement). >  for k = 2:1:length(cross)-1 >    cp = (499+ cross(k) + round((cross(k+1) - cross(k))/2)); >        ll = data((499 + cross(k))); >        hl = data((499 + cross(k+1))); >        ml = data(cp); > >        if (ml > ((hl+ll)/2) > Unbalanced parentheses? >               %ANYTHING ADDED IN HERE RETURNS PARSE ERROR >               %This is where I want to do the curve fitting > >            end > > > >  end > end > end > > > > This may be a bit hard to understand; it is dificult reading other peoples > code I know! > > Basically anything I put in the IF statement causes a 'parse' error. > > Any suggestions? > > Cheers > Martin > > ----- > Pretty much convinced Octave>Excel for scientific data analysis! > -- > View this message in context: http://octave.1599824.n4.nabble.com/Parse-error-tp2322504p2322504.html> Sent from the Octave - General mailing list archive at Nabble.com. > _______________________________________________ > Help-octave mailing list > [hidden email] > https://www-old.cae.wisc.edu/mailman/listinfo/help-octave> -- RNDr. Jaroslav Hajek, PhD computing expert & GNU Octave developer Aeronautical Research and Test Institute (VZLU) Prague, Czech Republic url: www.highegg.matfyz.cz _______________________________________________ Help-octave mailing list [hidden email] https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Open this post in threaded view
|

## Re: Parse error?

 In reply to this post by dirac On Thu, Aug 12, 2010 at 03:23:13AM -0700, dirac wrote: > > ... > > if (ml > ((hl+ll)/2) You have forgotten one closing paranthesis ... > >                %ANYTHING ADDED IN HERE RETURNS PARSE ERROR >                %This is where I want to do the curve fitting >       >             end _______________________________________________ Help-octave mailing list [hidden email] https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Open this post in threaded view
|

## Re: Parse error?

 In reply to this post by Jaroslav Hajek-2 I feel really silly now! Worked a treat, thanks so much Jaroslav and Laurent. I'll be more diligent with the brackets before posting in the future. Regards Martin Still learning everyday.
Open this post in threaded view
|

## Re: Parse error?

 --- On Thu, 8/12/10, dirac <[hidden email]> wrote: > From: dirac <[hidden email]> > Subject: Re: Parse error? > To: [hidden email] > Date: Thursday, August 12, 2010, 3:45 AM > > I feel really silly now! > > Worked a treat, thanks so much Jaroslav and Laurent. I'll > be more diligent > with the brackets before posting in the future. > > Regards > Martin > > ----- The point is not parenthesis in particular. The point is you should be able to debug such errors _yourself_, and the method is temporarily commenting out pieces of code until there is no parsing error. When it becomes clear which relatively big chunk of code is to blame (e.g. if ... endif), then the problematic chunk is gradually uncommented too by pieces which make sense, e.g. if CONDTION # BODY endif and in such a manner it finally becomes clear which lines are to blame. Regards,   Sergei.       _______________________________________________ Help-octave mailing list [hidden email] https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Open this post in threaded view
|

## Re: Parse error?

 Hi, I had worked out it was the IF statement prior to posting by using the method of commenting out pieces of code. Sometimes though it takes someone else to point out things as simple as the error I was recieving; for which I am very grateful. I apoligize, and I understand it was unnessasary to post, but after spending the whole morning on it I used the forum as a last resort. Like I said before, I am going to check and scrutinize more before I post here again. Thanks for the debugging tips though, I am getting more used to programming in general with all of your help :) Thanks MA Still learning everyday.
Open this post in threaded view
|

## Re: Parse error?

 --- On Thu, 8/12/10, dirac <[hidden email]> wrote: > From: dirac <[hidden email]> > Subject: Re: Parse error? > To: [hidden email] > Date: Thursday, August 12, 2010, 5:27 AM > > Hi, > > I had worked out it was the IF statement prior to posting > by using the > method of commenting out pieces of code. Sometimes though > it takes someone > else to point out things as simple as the error I was > recieving; for which I > am very grateful. I apoligize, and I understand it was > unnessasary to post, > but after spending the whole morning on it I used the forum > as a last > resort. Like I said before, I am going to check and > scrutinize more before I > post here again. Thanks for the debugging tips though, I am > getting more > used to programming in general with all of your help :) > > Thanks > MA > > ----- > Pretty much convinced Octave>Excel for scientific data > analysis! > -- FWIW, compile _often_. I.e. compile more or less after each completed 'if', 'for', etc block - the shorter the code/code addition is, the easier it is to catch (newly introduced) errors. Regards,   Sergei.       _______________________________________________ Help-octave mailing list [hidden email] https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Open this post in threaded view
|

## Re: Parse error?

 In reply to this post by dirac Another option is to use "smart" editors, like f.i. emacs with the octave-mode. This way, each time you hit enter, you can notice problems is the line you just typed is not indented correctly. Regards Pascal
Open this post in threaded view
|

## Re: Parse error?

 On 12 August 2010 09:53, CdeMills <[hidden email]> wrote: > Another option is to use "smart" editors, like f.i. emacs with the > octave-mode. Current octave-mode in Emacs needs a lot of work. The code for octave-mode has been gathering bit rot for a while. While it works ok, it definitely could work better. The code has been recently been moved from Octave's sources to Emacs' sources, but the problem seems to be that the general Emacs community at large has little use for it, since Octave and Matlab syntax seems to be much more of a niche than, say, Python or C++. I'll try to submit a patch to the emacs-devel list again for recognising single-quoted strings in octave-mode. It got ignored last time I submitted, probably due to the aformentioned lack of interest by the general Emacs community. _______________________________________________ Help-octave mailing list [hidden email] https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Open this post in threaded view
|

## Re: Parse error?

 In reply to this post by Jaroslav Hajek-2 HI Am trying to use octave to simulate an asset paths, however when i wrote my code and saved it in the script as an m-file, on running it at the octave prompt, it indicates parse error line 18 of file /home/user/AssetPaths.m, and more other parse & syntax errors as shown in the inserted image , to make it even more problem, when i try to access the editor via command prompt (edit AssetPaths.m) to start trying to correct errors, its not possible since it still indicates the parse error and syntax error issues. how can i go about to solve this problem to run my code successfully. this is the script. % Script to price an Asian put option using a Monte-Carlo approach. S0 =50;       % Price of underlying today X = 55;       % Strike at expiry mu = 0.04;    % expected return sig = 0.1;    % expected vol. r = 0.03;     % Risk free rate dt = 1/365;   % time steps etime = 50;   % days to expiry T = dt*etime; % years to expiry nruns = 1000; % Number of simulated paths % Generate potential future asset paths S = AssetPaths(S0,mu,sig,dt,etime,nruns); % Plot the asset paths time = etime:-1:0; plot(time,S,'Linewidth',2); set(gca,'XDir','Reverse','FontWeight','bold','Fontsize',24); xlabel('Time to Expiry','FontWeight','bold','Fontsize',24); ylabel('Asset Price','FontWeight','bold','Fontsize',24); title('Simulated Asset Paths','FontWeight','bold','Fontsize',24); grid on set(gcf,'Color','w');
Open this post in threaded view
|

## Octave's EDITOR variable

 On 12/09/2011 04:04 AM, Taza wrote: > http://octave.1599824.n4.nabble.com/file/n4175847/Asset_Paths_Simulation_errors.jpg> HI > > Am trying to use octave to simulate an asset paths, however when i wrote my > code and saved it in the script as an m-file, on running it at the octave > prompt, it indicates parse error line 18 of file /home/user/AssetPaths.m, > and more other parse&  syntax errors as shown in the inserted image , to > make it even more problem, when i try to access the editor via command > prompt (edit AssetPaths.m) to start trying to correct errors, its not > possible since it still indicates the parse error and syntax error issues. > how can i go about to solve this problem to run my code successfully. The 'edit()' function calls the editor defined by the Octave variable EDITOR, and your error messages look like you have it empty or set to the shell or octave itself. Try running Octave with EDITOR environment variable pre-defined to your favorite editor: EDITOR=nedit octave and type the 'edit AssetPaths.m' on the Octave command line. In principle, it should work to set the EDITOR within Octave, but when I do: EDITOR('vi') edit AssetPaths.m Octave still runs the original editor, not 'vi' even though Octave's EDITOR variable is correctly changed to 'vi'. By the way, you write that your script contains this line:  > plot(time,S,'Linewidth',2); but the error message reports error in the line reported as plot(time,S,); % a graph of asset price S against time so the file /home/user/AssetPaths.m does not contain what you think it contains. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave