It’s all about the data…
You have data, right? You want to analyze and manipulate the data using MATLAB, right? The question is, how do you import this data into MATLAB?
It turns out there are many answers to these questions and which import mechanism you use will depend on what you are trying to do. Lets look at several useful techniques for importing data into MATLAB.
Using the Command Window
The simplest (and most obvious) way to get data into MATLAB is to type it at the command line. For example:
Now you have some data assigned to the variables a and b in the MATLAB workspace. This technique works well if you’re going to use data that can be generated by MATLAB commands or you’re using small sets of data that can be hand entered.
Cut/Copy/Paste or Drag and Drop
If you have a larger set of data, perhaps a few pages worth of numbers in a text file, you may want to use Cut/Copy/Paste or Drag and Drop to bring the data into MATLAB.
Simply select the text in the text file and cut or copy (depending on whether you want the data to stay in the file) Then click the command window and press Ctrl-V (Cmd-V on Mac) to paste. Alternatively, select the text, click on the selection and drag it to the command window.
This tool was created to help you import data into MATLAB and can handle a wide variety of data types. It allows you to customize how the data will appear in MATLAB. The wizard walks you through the process of importing you’re data.
There are several ways to bring up the Import Wizard
- At the Command Line
% This will open the import wizard
- Via the File -> Import Data… menu item: You can bring up the import wizard by selecting File->Import Data…
- Via the File -> Open menu item: If you select a File->Open and choose a file with data in it, MATLAB will either import that data (such as from a MAT-file) or Open the import wizard to allow you to import that data (such as from a comma separated list file).
- Double-clicking a data file in the current directory browser: Double clicking in the current directory browser has the same effect as doing File->Open and then selecting the file did the double click on.
How do you get your data into MATLAB?
Happy Data Analysis!
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.