Skip to main content
  1. Blogs/

Code Collaboration Scheme

··4 mins· loading · loading · · ·
Morethan
MATLAB CUMCM
Morethan
Author
Morethan
Computer, Physic & AI
Table of Contents
MathModel - This article is part of a series.
Part 3: This Article
Summary of CUMCM 2024 competition experience, focusing on the A problem and the collaborative approach with MATLAB code improvement

Process Overview
#

graph LR; id1("Task Allocation")-->id2("VS Code Collaboration")-->id3("MATLAB Code Execution");

Task Allocation
#

There are two key points:

  1. Tasks are divided into two parts: a main part and a secondary part.
  2. Tasks should be independent of each other, meaning no dependencies between them.

Code Collaboration
#

Software Tools
#

  1. VS Code Editor, along with the Live Server plugin, MATLAB plugin
  2. MATLAB.

Naming Conventions
#

  1. Main function should be uniformly named main: The main function is the one that directly computes the final result, while others should be called auxiliary functions.
  2. Data processing code: This refers to code that does not return any value but generates data tables. It should start with data, e.g., converting solar altitude angle \(\phi\) to cosine value, dataCosPhi.
  3. Internal data conversion code: This should start with to, e.g., converting coordinates from a natural coordinate system to a Cartesian coordinate system StoXY.
  4. Plotting code: Code related to plotting graphs should start with fig.
  5. Testing code: Should start with test.
  6. For other special types of functions, they should be named based on their functionality. Functions that return boolean values should start with is, such as a collision detection function isCollided; functions that return other data should start with get.

File Documentation Comments
#

Except for the common types of files mentioned in the naming conventions (data, test, fig, main), all other files should include documentation comments.

The documentation should be concise yet clear. It generally includes a brief description of the function, the input parameters, and the output parameters.

If you’re unsure how to write documentation, you can use AI assistance.

Internal Variable Naming
#

Fixed Parameters
#

All fixed parameters should be placed in a config.m file located in the root directory for centralized management. Each parameter should be followed by a comment explaining its purpose, for example:

learningRate = 0.001; % Learning rate
batchSize = 32; % Batch size
numEpochs = 100; % Number of epochs

To use this configuration file in other code files, simply include the following line:

run('config.m');
Even the parameters are transformed into another file, the VS Code can also recognizes it and provide complement suggestion.

Function-Internal Parameters
#

All variables used within a function should be explicitly defined at the beginning of the function and should include brief Chinese comments.

If similar parameters are used across multiple files, make sure to use consistent naming, especially in AI-generated code. Use F2 in VS Code to rename them.

Code Formatting
#

Code formatting is mainly handled using the official MATLAB plugin. After you activate the plugin, press Shift+Alt+F to format your code.

Git Version Control
#

A GitHub repository needs to be created to store the entire project files. Although the Live Server plugin enables faster real-time code collaboration, it is still necessary to commit and save at key development milestones to maintain the ability to roll back code.

All Git version control operations are performed on the lead developer’s computer, while other supporting developers use the Live Server plugin for more immediate code collaboration.

  • Local commit to save small improvements
  • push operations are done in major increments

Code Execution
#

Thanks to the latest function of the plugin MATLAB, we can now directly run and debug in the VS Code IDE. Though there are some limitations, it deserves a standing ovation.

Other
#

AI Instruction Set
#

Since generative AI’s code style might differ from the project’s standards, if you need to generate an entire file, please include the following code standard instructions at the beginning of your request:

You are a mature and standardized MATLAB programmer. While correctly implementing the user's goal, you should follow these code standards:
1. Clear and concise file documentation comments: The documentation should include a brief description of the function, input parameters, and output parameters.
2. Function-internal variable names should be concise and easy to read.
3. All variables used within a function should be explicitly defined at the beginning of the function, with brief Chinese comments added next to them.

User's instruction:

Example Project
#

In order to develop a project as fast and well-defined as possible, I have created an Example Project which contains all the regulations mentioned before. You can directly change the files in the example project without mnemonic cost. 😄

Code Tips
#

  • Parallel Execution
    MATLAB supports multi-threaded computing. You can convert a typical for loop to a parfor loop for parallel execution.
The execution of parfor functions is subject to strict requirements. Please refer to the official documentation for more details.

Huge Table Process
#

The comment output of the Mathematical Model is a Huge table in .mat file, which is usually hard to abstract the target data.

Here I directly write a simply Python program, Data extractor, to automatically operate the huge table data. With tiny modification, you can get any data you want from the .mat file.

Utilizing the online LaTeX table editor, we can get the capacity to quickly insert the table data into your thesis.

MathModel - This article is part of a series.
Part 3: This Article

Related

Bayesian Optimization
··1 min· loading · loading
Morethan
Math MATLAB CUMCM
CUMCM 2024 Summary
··8 mins· loading · loading
Morethan
CUMCM Math
MySQL Basics
·5 mins· loading · loading
Morethan
MySQL