MATLAB Coder Onramp Issue - Section 4 Call C Code from MATLAB

Hi all,
I am currently running through some of the learning materails online for both MATLAB and Simulink. I have started going over the MATLAB Coder Onramp which goes through the mecanisms for generating C code from MATLAB. This is using the website based version of the courses and as such the MATLAB environement is within the web browser itself.
However, I seem to be stuck at section 4 "Call C Code From MATLAB - Verify Generated Code". The task asks the following,
To generate a MEX function, you don't need to specify a configuration because the codegen function generates MEX by default.
codegen fcn -args {var} -report
If your function has input arguments and you want a code generation report, you can continue using args and report.
Task
Generate MEX code for the detectpH function. Use I2 as the example input.
The code may take up to ten seconds to generate.
Now I have added my result and compared this to the "See Solution" and it is the same
codegen detectpH -args {I2} -report
However, when I select Submit, I get an error using Codegen. I have cleared my entry, closed and reopened the course and even copied and pasted the result from the "See Solution" too to make sure there were no spelling mistakes but still no luck.
I am wondering if this is an issue to do with the in browser environment perhaps?
I did have issues with generating the C code earlier in the course, but as the training allowed me to continune, I assumed this was going to be dealt with in the next sections.
Hopefully I am doing something daft and its a simple fix.
I have attached the Build Log for additional infromation.
Thanks,
Jason

3 Kommentare

I can duplicate. I'll report this internally.
I got the same problem.
I have the same issue.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Tushar Sharma
Tushar Sharma am 6 Jan. 2025

1 Stimme

Hi Jason,
I encountered a similar issue and found a workaround that seems to work well. You can add the "jit" flag at the end of the "codegen" command. This allows MATLAB Online to compile the MATLAB code into machine code at runtime, instead of interpreting it line by line.
For instance, to complete this task successfully, you can use the following line of code:
codegen detectpH -args {I2} -report -jit
Hope it helps!

4 Kommentare

Hi Tushar,
Many thanks for your reply to this post. Adding -jit seemed to fix the issue for me as well.
Although this may not be the expected fix for the issue, this will need reflecting in the course @Cris LaPierre so others do not have the same stopping block.
For reference, the codegen page is here >> codegen
And the point for -jit is referenced as the following;
Use just-in-time (JIT) compilation for generation of a MEX function. JIT compilation can speed up MEX function generation. This option applies only to MEX function generation. This option is not compatible with certain code generation features or options, such as custom code or using the OpenMP library.
Thanks,
Jason
Note - This issue occurs further in the same course.
Section 5. Adjust Function Inputs - Allow Different Input Sizes. Task 2 asks the following;
"Generate MEX code for the detectpH function. Use myargs to set the input type.
The code may take up to ten seconds to generate."
Again the result I had was the same as the "See Solution" but this did not work. Adding the -jit to the end fixed this issue.
codegen detectpH -args myargs -report -jit works for section 5
how about task 3? i already see solution but not woking

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

David
David am 18 Jan. 2025
Update to this. I'm actually in the middle of the MATLAB Coder Onramp. The '-jit' fixed several of the problems but in one of the exercises (Configure Generated Code -> Change Code Configuration Settings -> Task 3), if you leave off the -jit, you get an error about <limits.h> missing. However, if you add -jit, you still get that error plus this warning:
Warning: JIT compilation is supported only for MEX generation.
I emailed our MathWorks AE (who pointed me to this post) but he had left for the day and will be out at a conference next week.
Thanks,
David

3 Kommentare

Adding -jit is just a workaround for the original issue. MathWorks is aware of the issue and the appropriate development teams are already working on it.
already solve or not because i stuck at task 3 on section 5
Cris LaPierre
Cris LaPierre am 16 Mai 2025
Bearbeitet: Cris LaPierre am 16 Mai 2025
It is fixed. Note that in task 3, you are now using the mex file you created in task 2. If you passed task 2 succesfully, then codegen worked. Read the instructions carefully for task 3. There are 2 scripts open in the editor. Make sure you change tabs so the changes are made in pHstripscode.mlx

Melden Sie sich an, um zu kommentieren.

Cris LaPierre
Cris LaPierre am 3 Feb. 2025

0 Stimmen

The issue has been fixed. It is no longer necessary to add '-jit' to your solution.

Kategorien

Mehr zu Code Verification finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by