Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Improve speed of skew matrix calculation.

Subject: Improve speed of skew matrix calculation.

From: Richard Crozier

Date: 2 Jun, 2011 15:19:04

Message: 1 of 1

Can anyone suggest a way to improve the speed of the following small function which I must call many times:

% Compute a skew matrix from its axial vector Theta.
%
% function S = skewmat(theta)
%
function S = skewmat(theta)
    [m,n]=size(theta);
    if m*n == 3
        S=[ 0 -theta(3) theta(2); ...
            theta(3) 0 -theta(1); ...
            -theta(2) theta(1) 0];
    elseif m*n == 2
        S=[-theta(2) theta(1)];
    else
        error('theta must be a 3-vector');
    end
    return;
end


Specifically, it is the line:

        S=[ 0 -theta(3) theta(2); ...
            theta(3) 0 -theta(1); ...
            -theta(2) theta(1) 0];

which is the problem. I'm guessing it's impossible to improve this, but thought I'd ask anyway. I presume mexing the function will not give much benefit as it's all basic matlab operations already.

Thanks

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us