Menu

#50 symcoco: syntax error in Matlab 2023b

---
fixed
nobody
None
2023-10-27
2023-10-22
No

When running this file in Matlab 2023b, I obtain the error message

Error: File: modela_sym.m Line: 124 Column: 1
The function "modela_sym_rhs_1" was closed with an 'end', but at least one
other function definition was not. To avoid confusion when using nested
functions, it is illegal to use both conventions in the same file.

Best regards
Alois

3 Attachments

Related

Tickets: #50

Discussion

  • Jan Sieber

    Jan Sieber - 2023-10-22

    Dear Alois,
    This is a known problem with the old version (Mar2020) of symcoco [1]. I just downloaded your example files and the problem no longer occurs for symcoco attached to the the August 2023 version. Attached is the (renamed) output with the new version, which behaves (hopefully) correctly.
    Best,
    Jan
    [1] Unfortunately, from one Matlab version to another the symbolic toolbox function generator matlabFunction changed its output format, appending the "end" keyword. The new version performs a test with an example output to determine the output format, so should work with all matlab versions.

     
  • Alois Steindl

    Alois Steindl - 2023-10-23

    Dear Jan,
    thank you very much for your quick and helpful response!
    I downloaded and installed the new coco version on August 19; today I downloaded it again and the zip-files are identical. Still I get the error message with both Matlab 2023a and 2023b.
    I will try to find out what happens during the day.
    With kind regards
    Alois

     
  • Jan Sieber

    Jan Sieber - 2023-10-23

    That's strange. I downloaded from sourceforge, applied your modelprep and got a valid file. Double-check that, if you open sco_sym2funcs, at the bottom of the file is a test function, looking like below (it checks if "end" is appended). Make sure that you have the new sco_sym2funcs in your path.
    %% test if output creates fucntions with 'end' keyword
    function funend=sco_test_for_end()
    x=sym('x');
    y=sym('y');
    if sco_isoctave()
    newline=@()sprintf('\n'); %#ok<sprintfn>
    else
    newline=builtin('newline');
    end
    str=strsplit(sco_symcode({x*y},x,y),newline());
    funend=['',str{strcmp(str,'end')}];
    end</sprintfn>

     
  • Alois Steindl

    Alois Steindl - 2023-10-23

    Dear Jan,
    thank you very much for your patient treatment of the problem!
    I put a breakpoint at the end of funend and could observe, that the treatment of the newline character in string functions might be the problem: After splitting the string at the newlines, the newline character remains in the strings, so one gets 'end\n' (actually Matlab 2023b distinguishes between the placeholder '\n' and the actual newline character <nl>, so the second last entry in str is 'end<nl>'. Therefore strcmp gives false.
    The preferred was seems to use splitlines; I executed the commands </nl></nl>

    str2=splitlines(sco_symcode({x*y},x,y));
    funend2=['',str2{strcmp(str2,'end')}];
    

    in the debug session and append the saved file to this message,
    With kind wishes
    Alois

     
  • Jan Sieber

    Jan Sieber - 2023-10-23

    Mhm, it seems that the behaviour is operating-system dependent? What operating system are you using? (I had tried linux and Matlab online, can't check it on windows). In Matlab online the behaviour is as I expected:
    K>> strsplit(sco_symcode({xy},x,y),newline())'
    ans =
    9x1 cell array
    {0x0 char }
    {'function out1 = sys_0(in1,in2)' }
    {'%SYS_0' }
    {'% OUT1 = SYS_0(IN1,IN2)' }
    {'% This function was generated by the Symbolic Math Toolbox version 23.2.'}
    {'% 23-Oct-2023 15:33:38' }
    {'out1 = in1.
    in2;' }
    {'end' }
    {0x0 char }

    I hesitate to use splitlines as it exists neither in octave nor prior to 2016b. I may go for strncmp(str2,'end',3) instead of strcmp(str2,'end'). For now you can fix the problem in your own download as you suggested. I will ask Harry to do an update if you can confirm that the strncmp solution also works for you.
    Best,
    Jan

     
  • Alois Steindl

    Alois Steindl - 2023-10-23

    You are guessing right, I use Matlab in Windows. I just tried your suggestion with strncmp and that also works.
    Thanks again for your efforts!
    Alois

     
  • Harry Dankowicz

    Harry Dankowicz - 2023-10-27

    Thank you Alois for flagging this and Jan for fixing it! An updated release (coco_2023October26) has been posted with this update.

     
  • Harry Dankowicz

    Harry Dankowicz - 2023-10-27
    • status: open --> fixed
     
  • Alois Steindl

    Alois Steindl - 2023-10-27

    Dear Harry,thank you very much for your kind response and the fast treatment of the problem, I am really impressed.I guess, that it is actually a fault in Matlab on Windows, because the help entry for strsplit in Matlab states that "The substrings specified in delimiter do not appear
    in the output newStr." so I think I should send a bug report.I am learning coco and could already find a family of periodic solutions containg BPCs and LPCs. I still have to get familiar with the details, but coco makes a very good impression. Thanks to all of you.With kind wishesAlois------ Originalnachricht------Von: Harry DankowiczDatum: Fr., 27. Okt. 2023 03:40An: [cocotools:tickets];Cc: Betreff:[cocotools:tickets] #50 symcoco: syntax error in Matlab 2023bThank you Alois for flagging this and Jan for fixing it! An updated release (coco_2023October26) has been posted with this update.

    [tickets:#50] symcoco: syntax error in Matlab 2023b
    Status: open
    Milestone: ---
    Created:
    Sun Oct 22, 2023 08:12 PM UTC by Alois Steindl
    Last Updated: Mon Oct 23, 2023 02:51 PM UTC
    Owner: nobody
    Attachments:

    bug.mat (6.2 kB; application/octet-stream)
    modela_sym.m (4.0 kB; text/plain)
    modelprep.m (597 Bytes; text/plain)

    When running this file in Matlab 2023b, I obtain the error message
    Error: File: modela_sym.m Line: 124 Column: 1
    The function "modela_sym_rhs_1" was closed with an 'end', but at least one
    other function definition was not. To avoid confusion when using nested
    functions, it is illegal to use both conventions in the same file.

    Best regards
    Alois

    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/cocotools/tickets/50/
    To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

     

    Related

    Tickets: #50


Log in to post a comment.