### Matlab Programming for Engineers

Matlab programming for engineers uses command oriented, a prompt appears on the screen and a matlab statement can be entered. Matlab programming language is user friendly and accepts only vectors or arrays as inputs. Matlab has optional toolboxes that can be used to solve common problems.

Characteristics of Matlab:

• Automatic Memory Management
• Intuitive easy to use
• Many applications-specific toolboxes available

Characteristics of Matlab:

• Automatic Memory Management
• Intuitive easy to use
• Many applications-specific toolboxes available

Matlab programming for  Engineers:

Matlab environment is used to write code and also execute programs which is created by programmers. When matlab executes it can display several types of windows which accepts commands or display information. Matlab windows should provide help and allow the user to examine the values of variables defined in memory.

Steps for writing a program Matlab programming for Engineers:

1. Open a mat (.m) file in a matlab window
2. Select save option from file menu and enter file name to save a file
3. Saved files are accessed from workspace directory

System Requirements:

OS: Windows XP, Windows 7 (32-bit & 64-bit) and Windows 8

Disk Space: 345MB (Matlab only with help)

RAM: 256 MB (minimum) and 512 MB (recommended)

Example Code for Median Filtering:

Title(‘image with salt and pepper noise’);
Figure,imshow(a);
%Pad the matrix with zeros on all sides
Modifya=zeros(size(a)+2);
B=zeros(size(a));
%Copy the original image matrix to the padded matrix
for x=1:size(a,1)
for y=1:size(a,2)
modifya(x+1,y+1)=a(x,y);
end
end
%let the window be an array
%store the 3-by-3 neighbour values in the array
%sort and find the middle element
For i= 1:size(modifya,1)-2
for j=1:size(modifya,2)-2
window=zeros(9,1);
inc=1;
for x=1:3
for y=1:3
window(inc)=modifya(i+x-1,j+y-1);
inc=inc+1;
end
end
med=sort(window);
%place the median element in the output matrix
b(i,j)=med(5);
end
End
%Convert the output matrix to 0-255 range image type
B=uint8(b);
Title(‘image after median filtering’);
Figure,imshow(b);

Syntax for Image grayscale Conversion:
Conversion of RGB to grayscale:

I = rgb2gray(RGB)
newmap = rgb2gray(map)
Conversion of indexed image to grayscale:
I = ind2gray(X,map)
Example Code for Enhance Contrast in Color Image:
Parameters:
% Input, uint8 RGB(:,:,3), the original data.
%
% Input, real S, the sharpness. Normally, S is greater than 1.
% S < 1, the image is blurred.
% S = 1, the image is unchanged.
% 1 < S, the contrast is heightened.
%
% Output, uint8 RGB_CONTRAST(:,:,3), the data after contrast enhancement.
%
r = contrast_gray ( rgb(:,:,1), s );
g = contrast_gray ( rgb(:,:,2), s );
b = contrast_gray ( rgb(:,:,3), s );
rgb_contrast = zeros ( size ( rgb ) );
rgb_contrast = uint8 ( rgb_contrast );
rgb_contrast(:,:,1) = r(:,:);
rgb_contrast(:,:,2) = g(:,:);
rgb_contrast(:,:,3) = b(:,:);
return
end