How To Import Data From Excel To Matlab
Introduction of xlsread Matlab
'xls' command is used in Matlab to import and export excel files into Matlab. We can create the excel files by using this command as well every bit nosotros tin read the excel files by using this commands. there are two functioning in Matlab one is to create excel files and other is to read or open excel files. These commands are xlsread and xlswrite. Xlsread control is used to read or open the existing excel files in Matlab. Xlswrite control is used to write or create excel files in Matlab.by using xlswrite command we can too modify content of existing excel files. This command improves the adaptability of Matlab language by accessing data in other formats.
Syntax:
xlsread (filename)
xlsread (filename, parameters listing)
xlsread (filename, [data])
xlsread (filename, sheet name)
xlsread (filename, range for columns or row)
How does xlsread Piece of work in Matlab?
To read whatever excel file in Matlab first we need to create that file with some data in to it. There are diverse ways to write and read the excel files. These files tin can be written by sing parameter listing, directly information, by giving sheet name, or by giving a range of the columns or rows.
Steps to read excel file in Matlab –
- Clear workspace
- Declare and assign information
- Write into excel file past using 'xlsread' syntax( xlswrite (filename,[information])
- Declare variable to read a file
- Use xlsread read command by using syntax. ( xlsread (filename ) ).
Examples of xlsread Matlab
Following are the examples are given below:
Example #1
In this example, excel file is 'abc.xlsx' and information added to the file is [ 13 ,42, 53 ]. And so it create one excel file in current directory.
Matlab Editor | Command window |
Clc ; xlswrite('abc.xlsx ',[xiii, 42, 53]) xlsread (' abc.xlsx ') | ans = thirteen 42 53 |
Output:
Example #2
In this case input data is declared by using another variable, which is 'data' (information= [3 four vii 7;iv 3 2 two;four 56 78 32]) . Data is written in 'file1'.
Matlab Editor | Command Window |
Clc ; Data = [3 4 7 7 ; 4 three 2 2 ; iv 56 78 32] xlswrite(' file1.xlsx ', information) xlsread (' file1.xlsx ') | data = 3 4 vii vii 4 three 2 two 4 56 78 32 ans = iii 4 7 7 four 3 2 2 4 56 78 32 |
Output:
Example #3
In this example input data is declared by using some other two variables, which is 'data' (data1= [3 54 47 ;4 33 22; 56 7 42;43 7 one] and data2=[56 4 ii ; 5 4 2; 67 four ane;one 01 1]. Data is written in 'file2'.
Matlab Editor | Control Window |
Clc ; data1= [three 54 47 ; four 33 22; 56 7 42 ; 43 vii 1] data2 = [56 iv 2 ; 5 4 2 ; 67 four 1 ; i 01 1] xlswrite(' file2.xlsx ' , [data1 ; data2]) xlsread(' file2.xlsx ') | data1 = three 54 47 iv 33 22 56 7 42 43 seven 1 data2 = 56 4 two 5 4 2 67 iv one i i 1 ans = 3 54 47 4 33 22 56 vii 42 43 seven ane 56 four 2 5 4 2 67 four 1 one 1 one |
Output:
Example #four
In this example input data is declared by using another two variables , which is 'data' (data1= [iii 54 47 ;4 33 22; 56 7 42;43 vii 1]and data2=[56 four 2 ; 5 4 2; 67 4 i;i 01 i]). Data is written in 'file1'.to read the file we use range role. Past giving range to the specific file we can brandish only important data.
Matlab Editor | Command Window |
Clc ; data1 = [iii 54 47 ;4 33 22; 56 7 42;43 7 1] data2 = [56 iv 2 ; five 4 2 ; 67 4 1 ; ane 01 1] xlswrite('file2.xlsx',[data1 ; data2]) r = ' A3 : B2 ' a = xlsread('file2.xlsx', r ) | data1 = 3 54 47 four 33 22 56 7 42 43 7 i data2 = 56 4 2 5 4 two 67 iv ane 1 one ane r = A3:B2 a = iv 33 56 seven |
Output:
Example #five
In this example input data is alleged by using another 2 variables , which is 'data' (data1= [3 54 43 47 ; 4 33 32 22 ; 56 5 7 42 ; 11 23 7 ane] and data2 =[56 four 2 iv ;0 five 4 2; 67 1 iv 1;one 01 one 1 ]). Data is written in 'file3'.to read the file we use range part. Past giving range to the specific file we can display only important data. Here start range value and stop range value is same to we can display only specific row or column by using this method.
Matlab Editor | Command Window |
clc; data1= [3 54 43 47 ;iv 33 32 22; 56 5 7 42;11 23 7 i] data2=[56 iv 2 4 ;0 5 iv 2; 67 ane 4 1;1 01 1 1] xlswrite('file3.xlsx',[data1;data2]) r='C:C' a=xlsread('file3.xlsx',r) | data1 = three 54 43 47 four 33 32 22 56 5 7 42 11 23 seven 1 data2 = 56 4 2 4 0 v 4 2 67 1 iv ane one i 1 i r = C:C a = 43 32 7 seven 2 iv iv 1 |
Output:
Conclusion
Nosotros know that present a, almost of the data comes in excel format only, therefore to deal with excel files is footling difficult. Just past using Matlab nosotros tin can easily import and export the information from excel to Matlab or Matlab to excel. We tin read the excel information in various ways as per our need and as per application need. Matlab operates on excel data very effectively and efficiently.
Recommended Articles
This is a guide to xlsread Matlab. Here we as well talk over the introduction and how does xlsread work in matlab? along with different examples and its code implementation. you may also take a look at the following articles to learn more –
- xlabel Matlab
- Matlab mesh()
- Plot Vector Matlab
- Size Office in MATLAB
How To Import Data From Excel To Matlab,
Source: https://www.educba.com/xlsread-matlab/
Posted by: nelsonhisguallon.blogspot.com
0 Response to "How To Import Data From Excel To Matlab"
Post a Comment