File Handling
File Handling
File handling in MATLAB refers to the processes and techniques used to create, read, write, append,
and manipulate files (text or binary) stored on a disk. It allows for storing and retrieving data for
later use, sharing, or further analysis. MATLAB provides built-in functions for seamless file handling
that is also supported in GNU Octave.
o Modes include:
while ~feof(fileID)
disp(line);
end
fclose(fileID);
while ~feof(fileID)
line = fgetl(fileID);
disp(line);
end
1. Data Storage:
o Files can be used to store results of simulations or experiments for future use.
2. Data Sharing:
3. Automation:
4. Compatibility:
o Works with text, binary, and proprietary file formats like .mat.
Function Purpose
fopen Open a file.
fclose Close an open file.
fprintff Write formatted text to a file.
fscan Read formatted text from a file.
fgetl Read one line of text without
newline.
fgets Read one line of text including
newline.
fread Read binary data.
fwrite Write binary data.
textscan Read formatted data into cell
arrays.
feof Check for end of file.
ferror Check for file errors.
-Visualize images and results using functions like imshow and imagesc.
3. Image Analysis:
-Extract meaningful information using edge detection, region properties, and histograms.
4. Image Transformation:
5. Image Enhancement:
-Improve image quality using filtering, noise removal, and contrast adjustments.
6. Image Segmentation:
8. 3D Image Processing:
Function Purpose
imwrite Write an image to a file.
Imshow Display an image.
Rgb2gray Convert an RGB image to grayscale.
Imresize Resize an image.
Imrotate Rotate an image.
imcrop Crop a portion of an image.
Imfilter Apply filters to an image (e.g., Gaussian).
Edge Perform edge detection (e.g., Sobel, Canny).
Regionprops Measure properties of image regions.
Imadjust Adjust the contrast of an image.
Histeq Perform histogram equalization.
Bwlabel Label connected components in a binary image.
imsegkmeans Perform k-means clustering for segmentation.
Imread Read an image file.
img = imread('example.jpg');
figure;
imshow(img);
title('Original Image');
grayImg = rgb2gray(img);
enhancedImg = imadjust(grayImg);
figure;
subplot(1, 3, 1);
imshow(grayImg);
title('Grayscale Image');
subplot(1, 3, 2);
imshow(enhancedImg);
title('Enhanced Image');
subplot(1, 3, 3);
imshow(edges);
title('Edges Detected');
Output
4. Edges Detected: Highlights edges in the image using the Canny method.
1. Medical Imaging:
2. Computer Vision:
3. Satellite Imaging:
4. Robotics:
5. Industrial Automation:
1. Built-in Functions:
2. Visualization Tools:
3. Ease of Integration:
4. Platform Independence:
5. Extensive Documentation: