[related]

[Tweets]

12/02/2018 11:18am
Indeed! [LINK]
08/02/2018 4:07pm
The advert video for @iros_2018 is really good! I wish robots really served coffee at the conference [LINK]
07/02/2018 10:10am
RT @NatureEcoEvo: Cockroach and termite genomes reveal molecular basis of termite eusociality [LINK] [LINK]
06/02/2018 1:29pm
Robotics for Nuclear Environments - a really cool website for a really cool project that I am currently a part of a… [LINK]
02/02/2018 8:09pm
RT @RIFBristol: Everything you need to know about Bristol’s sci-tech scene [LINK] via @siliconrepublic [LINK]

[Basic Matrix Operations]

Date: Nov 2011
Tags: Matlab

I put this together when I revisited working in Matlab as a reference and a quick look up of mostly used functions. All of these are compatible with Octave as well.

Creating matrices

% Produce 2x3 matrix of ones
A = ones(2,3)

% Produce 2x3 matrix of twos
A = 2*ones(2,3)

% Produce 2x3 matrix of 0s
A = zeros(2,3)

% Produce 2x3 matrix of random numbers
A = rand(2,3)

% Produce 2x3 matrix of gaussian numbers with mean 0 and variation 1
A = randn(2,3)

% Produce large vector of gaussian numbers
A = -6 + sqrt(10)*(randn(1,10000));

% Print histogram
hist(A)

% Produce 3x3 matrix of random numbers from <-1;1>
A = rand(3,4);

% 5x5 identity matrix
I = eye(5)

% Magic square (all columns, rows, diagonals sum up to same number)
MAGIC = magic(3)

Operations on matrices

% Everything in 2nd column
A (:,2)

% Everyting from 1st and 3rd row, all columns
A([1 3],:)

% Append another column vector
A = [A, [100; 101; 102; 103]]

% All elements of A into single column vector
B = A(:)

% Invert matrix
C = pinv(A)

% Transpose matrix
D = C'

% Element-wise multiplication (works with other signs too):
E = rand(2,3)
F = 2*ones(2,3)
G = E .* F

% ElementwiseLogarithm of matrix
log(E)

% Elementwise Exponentiaion
exp(E)

% Element wise minus E = -E

% Elementwise Absolute values
abs(E)

% Elementwise adding
e = [2;4;5;7]
H = e + ones(length(e),1)
I = E + 1

% Max value of vector
a = [1 34 6 2]
val = max(a)
[val, index] = max(a)

% Element-wise comparison (returns true/false)
a < 3

% Element-wise comparison (returnse elements)
find(a < 3)

% Add up elements
summation = sum(a)

% Mulitply elements
product = prod(a)

% Floor elements
FLOORING = floor(a)

% Ceil elements
CEILING = ceil(a)

% Column- and row- wise maximums where last argument is dimension
columnWiseMaximums = max(A,[],1)
rowWiseMaximums = max(A,[],2)
maximumElement = max(A(:))

% SumUp elements to create vector
sumOfColumns = sum(MAGIC,1)
sumOfRows = sum(MAGIC,2)

% Diagonal sum, first multiply by identity matrix to make all
% elements expect of diagonal 0
MAGIC .* eye(3)
sumOfDiagonal = sum(sum(MAGIC.*eye(3)))

Measuring matrices

% Size of matrix
S = size(A)

% Size of rows
S = size(A,1)

% Size of columns
S = size(A,2)

% Size of longer dimension
S = length(A)


{Please enable JavaScript in order to post comments}

[You might also be intested in...]

V-REP, Gazebo or ARGoS? A robot simulators comparison
Let’s have a look at three commonly used open-source simulators for robotics: V-REP, Gazebo and ARGoS, to find out which one suits your project the best.
Designing Effective Roadmaps for Robotics Innovation
Automated factories, autonomous delivery drones, self-driving cars: these and similar technologies will soon touch every aspect of our lives. An engaging discussion about how these technologies are regulated and innovated took place at the IROS 2017 conference.
The Information-Cost-Reward framework for understanding robot swarm foraging
The Information-Cost-Reward (ICR) framework relates the way in which robots obtain and share information about where work needs to be done to the swarm’s ability to exploit that information in order to perform work efficiently in the context of a particular task and environment.
Behaviour-Data Relations Modelling Language For Multi-Robot Control Algorithms
Behaviour-Data Relations Modeling Language (BDRML) explicitely represents behaviours and data that robots utilise, as well as relationships between them. This allows BDRML to express control algorithms where robots cooperate and share information with each other while interacting with the environment.
Robot swarms in action
Watch e-puck robots collect resources and bring them back to base. While the previous simulation work helped us to learn a lot about the advantages and disadvantages of communication in swarms, doing similar experiments with real robots is already revealing interesting new things.