Skip to content

Matlab Standards

All MatLab scripts shall start with a header like so

%% Script title
% Author(s) and date
%
% What the script does
% Briefly describe inputs and outputs

Requirements interface steup

In the code folder, you will find three scripts that you will need to add to the start of your script in order to make it work with the requirements and results folder req.

  • SETUP.m
  • SAVE_NUMBER_TO_TXT.m
  • LOAD_CONSTANTS.m

Setup file SETUP.m

This file will link your script to the shared requirements folder of the launcher to be designed.

  • PATH_REQ_FOLDER should be set to the /req/ folder address in your system
  • PATH_CONSTANTS should be set to the /const/ folder address in your system

The functions are

  • READ_REQ(REQ_NAME): Assigns a requirement value to a variable
  • SAVE_REQ(REQ_NAME, VALUE): Saves a value to the requirement file

Constants file LOAD_CONSTANTS.m

When called into your script it will load all physical constants shared by the team.

How to use the interface

Importing values

Every script, after the header, shall import the values it needs from the project (which must be either constants or requirements set by the team or generated by some other script) as follows:

% Importing requirements as constants
SOME_REQUIREMENT_VARIABLE = READ_REQ('SOME_REQUIREMENT_VARIABLE');
TARGET_ALTITUDE = READ_REQ('SFR_MISSION_TARGET_ALTITUDE');
TARGET_MASS = READ_REQ('SFR_MISSION_TARGET_MASS');
TARGET_ALTITUDE_MARGIN_OF_SAFETY = READ_REQ('SFR_MISSION_ALTITUDE_MARGIN_OF_SAFETY');

This style ensures that variables names are indicative and shared (can be easily copied and pasted from one script to another and shows visibly which inputs a script requires.

(Optional) Renaming Values for Shorter Equations

Values inside the script can be renamed

x = SOME_REQUIREMENT_VARIABLE;
h = TARGET_ALTITUDE;

This allows to easily load the interface for a script already written without the requirements interface in mind, and without having to rename the variables inside the formulas.

In general it is more common to write formulas with symbols instead of requirement names.

Do the math

Here the magic happens.

Save results

All results should be saved to a file, whether text (value) or image (plot), and not just kept in memory.

To save values, the Requirement Interface is used as follows.

First rename the variables to a meaningful name:

TARGET_DELTA_V = v0;
PROPELLANT_MASS_RATIO = mprop_mi;

Then save them to a text file, which will go inside the requirements folder. Always try to keep the variable name and filename equivalent for easier use in other scripts.

SAVE_REQ('SOME_REQUIREMENT_VARIABLE', SOME_REQUIREMENT_VARIABLE)
SAVE_REQ('SFR_MISSION_TARGET_DELTA_V',TARGET_DELTA_V);
SAVE_REQ('SFR_MISSION_TARGET_TOTAL_IMPULSE',TARGET_TOTAL_IMPULSE);

Warning

This last step overwrites files without asking. You must be sure the script does the right math before committing.

Read the following 10 times:

All scripts should create new requirements. No script should overwrite a requirement that was there before it.