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 Import Data
 

Matlab Import Data

Priya Pedamkar
Article byPriya Pedamkar

Matlab Import Data

Introduction to Matlab Import Data

Import is the MATLAB function which is used to import the data in different forms like txt, jpg, etc. Also, we can import the data from Clipboard using the import function. In many applications, we need various files or databases as input. These kinds of applications won’t work or operate without an import function. All types of input data is accessible in the import function. We can use text files, excel files, notepad, and also images in different formats. The basic syntax of the import function is ‘import data’. Along with import data, we can give the name of the file which we are going to use in our program.

 

 

Syntax:

Watch our Demo Courses and Videos

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

There are following syntaxes to import the data into Matlab:

  • X = importdata( filename ), loads data into array X.
  • X = importdata( ‘-pastespecial’ ), loads data from the system clipboard not in the file.
  • X = importdata( ___, delimiterIn ), interprets delimiter Inas the column separator in ASCII file, filename, or the clipboard data. You can easily use delimiter In with any of the input arguments in the above syntaxes to import the data.

How to Create Matlab Import Data?

You can import data into MATLAB using different ways like

1. From a file

Do one of the following process to import data from a file:

  • Select Import Data on the Home tab, in the Variable section.
  • Double-click a file name to browser Folder.

2. From the clipboard

Do one of the following to import data from the clipboard:

  • Click on the Workspace browser title bar and then select Paste.
  • And Call import function with proper syntax.

Example to Implement Matlab Import Data

Below are the examples of Matlab Import Data:

Example #1 

Let us see one example, in this example, we import an image and display it using the import data function. Basically in this example, we take that image name with extension take that name into a single inverted comma and assign it to the filename1. We import the data from that filename1 which basically stores the image. Then we can take a variable namely ‘ X’, in X we can store the imported data from filename1, for importing data we use an import data inbuilt function which is available on MATLAB. Then simply we display that image using image function, image function is used to display the image. We pass that variable which stores the imported data into image function to display the image.

Code:

clc ;
clear all ;
close all ;
X = importdata ( ' download.jpg');
Image(X)

Output:

Matlab Import Data Example 1

Explanation: As we seen the resultant image is the same as the original image. The resultant image is nothing but the imported data image which we store into the variable X.

After the example 1 we can see the  Import a Text File.

Example #2

Let us see another example, in this example, we Import a Text File( mydoc01.txt) and Specify Delimiter and Column Header method “ using import data function. Basically, in this example, we take that filename with extension take that name into a single inverted comma and assign it to the filename1. We import the data from that filename1 which is basically stores the data. Then we can take a variable namely ‘ A ’, in A we can store the imported data from filename1, for importing data we use an import data inbuilt function which is available on MATLAB. Then simply we display that data, disp function is used to display the image. We pass that variable which stores the imported data into disp function to display the data

Code:

clc;
clear all;
close all;
filename = 'mydoc01.txt';
delimiterIn = ' ';
headerlinesIn = 1;
A = importdata(filename,delimiterIn,headerlinesIn);
for k = [3, 5] disp(A.colheaders{1, k})
disp(A.data[:,k])
disp(' ')
end

Output:

Matlab Import Data Example 2

 After the example 2, we can see the Import a Text File and Return Detected Delimiter method.

Example #3

Let us see another example, in this example, we Import a Text File( mydoc01.txt) and Return Detected Delimiter method “ using import data function. Using a text editor, create a comma-delimited ASCII file called mydoc01.txt.

Code:

clc;
clear all;
close all;
filename = 'mydoc01.txt';
[A,delimiterOut]=importdata(filename)

Output:

Return Detected Delimiter Method Example 3

Conclusion

In this article, we saw the basic concepts about what is import data in Matlab And how we use an import function in Matlab. What exactly syntax is used to import data in Matlab. In this article, we also saw some of the examples related to import data with Matlab codes and also saw related outputs about it.

Recommended Articles

This is a guide to Matlab Import Data. Here we discuss the basic concepts of Matlab Import Data and its Syntax along with different Examples and its Code Implementation. You can also go through our suggested articles to learn more –

  1. What is Switch Statement in Matlab?
  2. Plot Vector Matlab
  3. Matlab sphere() | Syntax and Examples
  4. Examples of Matlab Figure

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