Progressions can be created using the Colon operator
min = 10
max = 100
steps = 20
step_size = (max-min)/steps
i = min:step_size …
It is quite common to detect how many input arguments have been passed to a function, using nargin
(N arguments …
Matlab always use to open text files in tabs in the same editor window. When switching to 2014a documents started …
read moreTo set each constant in a model to sample time -1:
blks = find_system(dut, 'BlockType', 'Constant');
for i = 1:length …
find_system('BlockType', 'Gain')
This will list all gain blocks in currently loaded models. to limit to a particulat model:
find_system …
To add X and Y grids to plots :
grid on;
To add Y only grid:
set(gca,'XGrid','off','YGrid …
Wrap strings with sprintf
to allow the \n
to be escaped correctly.
>> disp('hello\nworld')
hello\nworld
>> disp(sprintf('hello …
When a script or function is called with run(./relative/path/script)
the working directory is changed to the ./relative …
Checking if an Array contains a number:
input = [1,2,3,4];
check = 4;
any(input==4)
Check if a …
read moreUsing Matlab to splitting data into odd and even samples.
A for loop approach:
data_odd = [];
data_even = [];
for i = 1:length …
For adding leading zeros to a number the following can be used for 4 decimal places with integer input:
dat …
To wrap a function with variable input arguments and pass them all on to the wrapped function. Based on a …
read moreIn ruby we can perform schwartzian transforms easily with the sort_by method. This allows sorting enumerators by any property.
For …
read moreHandling functions with extraneous leading outputs. For example:
function [a,b] = dummy_function
a = 10;
b = 20;
endfunction
[a, b] = dummy_function …
To shuffle a:
a(randperm(length(a)))
Example:
a = [10 2 5 20];
a = a(randperm(length(a)))
a =
5 …
I do not think that there are any magic bullets, best practises can minimise risk but you have to fully …
read moreMathworks Article on Object-Oriented programming for Matlab.
A quick example of the syntax:
classdef sads
properties
Name
SampleRate
end
properties …
When plotting several lines in Matlab, I have become aware of how hard it was to see the colours in …
read moreIn the following example we test the allocation speed of different types:
samples_to_avg = 10000;
for i=1:samples_to_avg
tic; t …
repmat(matrix, [repeat_y, repeat_x])
Horizontal
repmat([1 2 3],[1,4])
ans =
1 2 3 1 2 3 1 2 …
Running the Simulink model model.mdl from matlab for a specified time:
sim('model', stoptime)
Where stoptime is a number …
read moreA typical work flow in Matlab involves a folder filled with scripts and functions. Over time this folder grows until …
read moreTesting a matlab array for equality can be doen a few different was some have surprising side effects if your …
read moreMatlab figure properties which can be set through the properties editor can also be set by scripts. My main stumbling …
read more