## Turning y axis upside down in MATLAB

The ‘YDir’ axes property can be either ‘normal’ or ‘reverse’. By default it is ‘normal’ for most plots, but some plots will automatically change it to ‘reverse’, such as the image or imagesc functions. You can set the y-axis direction of an axes with either the set function or dot indexing (in newer MATLAB versions): … Read more

## Automatically maximize a figure

This worked for me: figure(‘units’,’normalized’,’outerposition’,[0 0 1 1]) or for current figure: set(gcf,’units’,’normalized’,’outerposition’,[0 0 1 1]) I have also used MAXIMIZE function on FileExchange that uses java. This is true maximization.

## MATLAB Compiler vs MATLAB Coder

MATLAB Compiler encrypts and archives your MATLAB code (which remains as MATLAB .m code), and packages it in a thin executable (either .exe or .dll) wrapper. This is delivered to the end user along with the MATLAB Compiler Runtime (MCR). If you wish, the MCR can be packaged within the executable as well. The MCR … Read more

## Random points inside a parallelogram

The question by the OP is a bit ambiguous so the question I will answer is: How to generate a point from a uniform distribution within an arbitrary quadrilateral, which is actually a generalization of How to generate a point from a uniform distribution within an arbitrary (convex) polygon. The answer is based on the … Read more

## How to initialize an array of structs in MATLAB?

Using repmat is by far the most efficient way to preallocate structs : N = 10000; b = repmat(struct(‘x’,1), N, 1 ); This is ~10x faster using Matlab 2011a than preallocating via indexing, as in N = 10000; b(N).x = 1 The indexing method is only marginally faster than not preallocating. No preallocation: 0.075524 Preallocate … Read more

## How to use SIFT algorithm to compute how similar two images are?

First, aren’t you supposed to be using vl_sift instead of sift? Second, you can use SIFT feature matching to find correspondences in the two images. Here’s some sample code: I = imread(‘p1.jpg’); J = imread(‘p2.jpg’); I = single(rgb2gray(I)); % Conversion to single is recommended J = single(rgb2gray(J)); % in the documentation [F1 D1] = vl_sift(I); … Read more

## Performance Tradeoff – When is MATLAB better/slower than C/C++

I have been using Matlab and C++ for about 10 years. For every numerical algorithms implemented for my research, I always start from prototyping with Matlab and then translate the project to C++ to gain a 10x to 100x (I am not kidding) performance improvement. Of course, I am comparing optimized C++ code to the … Read more

## How do I get the handles of all open figures in MATLAB

There are a few ways to do this. One way to do this is to get all the children of the root object (represented in prior versions by the handle 0): figHandles = get(groot, ‘Children’); % Since version R2014b figHandles = get(0, ‘Children’); % Earlier versions Or you could use the function findobj: figHandles = … Read more

## Octave/Matlab: Adding new elements to a vector

x(end+1) = newElem is a bit more robust. x = [x newElem] will only work if x is a row-vector, if it is a column vector x = [x; newElem] should be used. x(end+1) = newElem, however, works for both row- and column-vectors. In general though, growing vectors should be avoided. If you do this … Read more

## String to variable name MATLAB

Use eval(): var = eval(strcat(‘x’,’a’)); It will “evaluate” the string ‘xa’ and translate it to the value of the variable xa. Source : MATLAB documentation