### Reading 16-bit color avi video format in MatLab

You may have problems when reading .avi video using MatLab function aviread(). If you have 16-bit color video, aviread() can’t read it correctly. You can receive only grayscaled data using this function in this case. The solution is to use Kelly Kearney’s aviread16bitcol() function, which you can download from here: http://www.mathworks.com/matlabcentral/fileexchange/9314

Monday, December 29th, 2008

### Matlab. Adding annotations to graph’s points.

If you need to display any value or text (for example current point’s value) near different points of your graph in MatLab, you can use text(x,y,’string’) function.

For example:

```x = -pi:pi/10:pi; y = sin(x); figure('Name', 'Sample graph'), plot(x, y, '--rs'); % Label some points for i=8:size(x,2)-8 text(x(i), y(i), ['\leftarrow (', num2str(x(i)), ';', num2str(y(i)), ')']); end```

Here is the output:

Tuesday, November 25th, 2008

### Finding matrix’s max or min element in MatLab

Function max(A) (or min(A)) return a row vector with maximum (minimum) elements from each column of matrix A. If you need to find largest or smallest element in the vhole matrix, you should use max() or min() function once again: max(max(A)) or min(min(A)).

Sunday, May 18th, 2008

### Distance measurement between two locations on Earth in MatLab

Suppose, you need to calculate distance between two locations on Earth in kilometers. And suppose you know their geographical coordinates, i.e. [latitude, longitude]. In MatLab there is a function distance(lat1, lon1, lat2, lon2). It calculates distance between two points in angle units (in degrees there). So, you can calculate distance between two objects in angle units. Next you should to convert angle units into kilometers. Use for this distdim(angle,’deg’,’kilometers’) function.

For example you need to find distance between Minsk, Belarus (53.9, 27,5667 [53° 54′ 0″ N, 27° 34′ 0″ E]) and Caracas, Venezuela (10.5207, -66.9245 in [10° 31′ 14.52″ N, 66° 55′ 28.2″ W]).

Type:

`>> distdim(distance(53.9, 27.5667, 10.5207, -66.9245),'deg','kilometers')`

Result will be 9355.484 kilometers.

Wednesday, March 19th, 2008

• ## Info

Need programming help or consulting? Hire us