EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial Matlab File Extension
 

Matlab File Extension

Updated March 13, 2023

Matlab File Extension

 

 

Introduction to Matlab File Extension

A file name extension or simply file extension is present as a suffix in the end of a file name and comes after a period (.) and is mostly 2 to 4 characters in length. We can easily notice these extensions while opening a picture or document, by checking the name of the file. Operating systems use file extensions to identify the applications that are associated with the file types i.e. it is identified which application will be opened when we double click on the file.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Below is the table showing some of the file extensions supported by MATLAB:

Content of the File Extension Details
MATLAB formatted data
  • .MAT
MATLAB workspace
Text
  • TXT, CSV etc
  • Comma separated values
  • Delimited values
  • Combination of numbers and text
Spreadsheet
  • XLSM
  • XLSX
  • XLS
  • Data stored in the excel
Extensible mark-up language
  • XML
  • Formatted text in XML
Image files
  • Tif
  • Image formats like ‘tif’, ‘jpeg’, ‘gif’ etc. are supported

Let us now understand the syntax to open or load some of these file extensions in MATLAB:

Syntax:

  • Load (file)
  • Imread (file)
  • readmatrix

Description:

  1. Load(file) is used to load the variables present in the input file with ‘.MAT’ extension into our workspace
  2. Imread (file) will read the image which is specified by the argument ‘file’. Since we have not passed any format argument in this syntax, it will infer the format from the contents of the file
  3. Readmatrix is used to open a spreadsheet or a file with extensions like ‘XLSM’, ‘XLSX’, ‘XLS’

Examples of Matlab File Extension

Let us now understand the code to read a file with .MAT extension in MATLAB using ‘Load(file) function’.

Example #1

In this example, we will load data from a file ‘gong.mat’ which is present in MATLAB’s directory. Below are the steps to be followed:

  1. Check the existing contents of the workspace
  2. Check the contents of the ‘gong.mat’ file
  3. Load the ‘gong.mat file’

Code:

disp('Before our file is loaded:')
whos

[Getting the existing contents of the workspace]

disp('gong.mat file:')
whos('-file','gong.mat')

[Getting the contents of the input file to be loaded]

load('gong.mat')

[Loading the file with .MAT extension]

disp('After our file is loaded:')
whos

[Checking the contents of the workspace after loading the file]

Input:

disp('Before our file is loaded:')
whos
disp('gong.mat file:')
whos('-file','gong.mat')
load('gong.mat')
disp('After our file is loaded:')
whos

Output:

 Matlab File Extension-1.1

As we can see in the output, the contents of the file with .MAT extension are now loaded into our workspace.

Let us now understand the code to read a file with .tif extension. As this is an image file, we will be using ‘imread’ function.

Example #2

In this example, we will read the image of a moon from the ‘moon.tif’ file which is present in MATLAB’s directory. We will follow the following 2 steps:

  1. Call the imread function; this will read the image
  2. Call the imshow function; this will display the moon’s image into our workspace

Code:

A = imread(‘moon.tif’)

[Calling the imread function to read the file with ‘.tif’ extension]

imshow(A)

[Calling the imshow function; the image read in the first step is passed as an input to the imshow function. This will display the image into our workspace]

Input:

A = imread(‘moon.tif’)
imshow(A)

Output:

Matlab File Extension-2.1

2.2

As we can see in the output, we have obtained image of the moon, which was read by us from MATLAB’s file with ‘.tif’ extension.

Let us now understand the code to read a file with .txt extension. We will use ‘readmatrix’ function for this purpose.

Example #3

In this example, we will read contents of the file ‘basic_matrix.txt’ which is present in MATLAB’s directory.

Code:

A = readmatrix('basic_matrix.txt')

[Calling the readmatrix function to read the file with ‘.txt’ extension] [‘basic_matrix.txt’ file contains a 5 x 4 matrix. The above line of code will display this matrix into our workspace]

Input:

A = readmatrix('basic_matrix.txt')

Output:

 3.1

As we can see in the output, we have obtained a 5 x 4 matrix which is read by us from a file with ‘.txt’ extension.

Next, we will learn how to change a file’s extension. This can be done by following the below mentioned steps:

  • List all your files whose extensions you want to change in the directory
  • Put the extension as ‘.out’
  • Copy this file and then change its extension to the extension you want (for our understanding we will use ‘.txt’ extension)
  • Delete the file with .out extension

Below is the code to change the extension of multiple files in one go:

directory = 'C:\Users\name\Documents\MATLAB';
listOfFiles = dir([directory, '*.out']);

[Give the names of all the files whose extensions are to be changed]

for i = 1 :numel (listOfFiles)
file1 = fullfile(directory, listOfFiles(1).name);
[temporaryDir, temporaryFile] = fileparts(file1);
status = copyfile(file1, fullfile(temporaryDir, [temporaryFile, '.txt']))

[Loop to copy all .out files and give them ‘.txt’ extension]

delete(file)

[Deleting the file with ‘.out’ extension]

end

Recommended Articles

This is a guide to Matlab File Extension. Here we also discuss the introduction and syntax of matlab file extension along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. MATLAB Unique
  2. Matlab Root Finding
  3. MATLAB Normalize
  4. Curve Fitting Matlab

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW