This guide will instruct you on creating a simple script in MATLAB to create a list of 3 row vector variables which will be useful to call up later. This guide takes you through the basics of using the command window, workspace, current folder, variable editor and editor. If you just need the script it is available at the bottom.
Default MATLAB Colours?
All colours are made from a mixture of three primary colours:
A colour can be expressed as a
row vector opposed to a pre-existing string.
MATLAB has the following strings for the primary and secondary colours:
Black is shown in the absence of these three colours and white is shown when these three colours are at full brightness.
8 Bit 0:255
Many programs such as Microsoft Office list colors in 8 bit, which means they list levels. If we subtract 1 from 256 to get a 0 value with range from 0-255. We may use the colour pickers in Microsoft Word to determine the colour we want to use. Select the button to change the colour of the text, select More Colours:
Select your colour and then select custom:
You now get your RGB values listed from 0 to 255.
We can create a row vector using the three numbers shown above however we need to normalise them dividing through by 255.
Now we get the variable mw_wine we can double click on it, in the workspace to view it in the variable editor:
We are now going to close down the variable editor.
Creating a Script File
Now we are going to create a new script in the current folder:
This will open up the Editor:
We can now type in a comment and the same line as code as before:
Now how the file name in the editor shows ending in a * this * means the file is unsaved. When we save the file the * will disappear:
If we clear all variables using the command
And clear the command window using the command
Now we have no variables open in the workspace or any command history:
Now we can type in the name of the script
The variable mw_wine is created and shows in the workspace and in command window history:
Now we can add additional colours
When we launch customcolours we see all these variables listed:
Creating a Second Script and Calling Up the First Script
We can now create a second script called testscript
In the first line we will leave a comment and then call up the first script
We will then generate a simple line plot (more details later) and colour it with one of the colours from customcolours
We can now change the colour and relaunch the code:
And change it again:
Of course we don't need the names of all the colours to flood the command window when we call up customcolours to prevent this we can end the lines in a semicolon
If we now run customcolours (this time by right clicking the script file and selecting run):
We see all the variables created but the command window is clean:
save as customcolours.m
%% This script will load custom colours from Microsoft Word