Anda di halaman 1dari 5

EXPERIMENT NO.

2 | Talha Nasim|GEE1731045

AIM – TO READ THE DATA FROM EXCEL FILE IN MATLAB AND PLOT THE 2D & 3D GRAPH.
APPARATUS REQUIRED – PC loaded with MICROSOFT EXCEL and MATLAB.

THEORY:-
Microsoft Excel provides a user-friendly method of entering, storing and organizing a large variety
of data. Transferring Excel data into MathWork's MATLAB technical analysis suite opens up a new
range of advanced methods of data analysis. MATLAB contains convenience methods for easily
importing data from MS Excel and other standard data formats.
 Steps to read excel file in MATLAB
1. Locate the Excel data file, with file extension ".xls," on your computer. MATLAB cannot import
data from the Excel executable directly and must know the location of the data file for import. If
you are unable to locate the correct data file, contact your system administrator.
2. Open the MATLAB executable.

3. Launch the MATLAB Data Import Wizard by selecting "Import Data..." from the File menu or by
entering the command "uiimport" into the MATLAB command prompt.

4. Navigate the file system to select your Excel data file. Click "Open" on the dialog box to have
MATLAB display a preview of data in the file.

5. Select the desired worksheet from the Excel file for import using the radiobox input of the left
side of the import wizard dialog box. Choose the columns and rows from the spreadsheet you wish
to import by selecting them on the right side of the import wizard dialog box.

6. Click "Next" on the dialog box to preview the imported MATLAB variables. Deselect any variables
you do not wish to import, and rename them to your specifications. Click "Finish" to finish
importing your Excel data.

7. Use the "xlsread()" function to import Excel data in a work flow without requiring user input.

[num_data, text_data, raw_data] = xlsread(my_filename, sheet_num, data_range);

The "num_data" variable contains a numeric array with the numeric data from the spreadsheet.
The "text_data" contains a cell array, MATLAB's multiple-data-type array, with the text data from
the spreadsheet. The "raw_data" variable contains all data in a cell array.
EXPERIMENT NO. 2 | Talha Nasim|GEE1731045

Command keyword

To plot 2d graph
close all;
clc;
data1= xlsread('data1.xlsx');
plot(data1)

EXAMPLE:1
TABLE NO.-1
X Y
-6 45
6 34
45 54
34 65
87 23
45 45
97 67
23 87
45 33
65 12
74 34

2DPLOT

100

80

60

40

20

-20
0 5 10 15 20 25

FIGURE 2.1
EXPERIMENT NO. 2 | Talha Nasim|GEE1731045

To plot 3d graph
close all;
clc;
data2= xlsread('data2.xlsx');
surf(data2)
colormap(jet) % change color map

EXAMPLE-2
TABLE NO.-2
X Y Z
65 85 34
76 86 65
54 34 87
98 34 12
23 45 45
76 77 67
98 87 98
76 43 65
45 97 8
76 54 76
3D PLOT

100

80

60

40

20

0
10
3
5 2.5
2
1.5
0 1

FIGURE-2.2
EXPERIMENT NO. 2 | Talha Nasim|GEE1731045

To plot separate x,y plot


close all;
clc;
data3= xlsread('data2.xlsx');
x=data3(:,1);
y=data3(:,2);
plot(x,y)

EXAMPLE-3
TABLE NO.-3
data1 data2
33 76
54 28
65 49
76 83
34 49
87 56
34 87
87 34
45 76
87 8
45 45
56 45
36 34
87 54
2D PLOT

100

90

80

70

60

50

40

30
20 30 40 50 60 70 80 90 100

FIGURE-2.3
EXPERIMENT NO. 2 | Talha Nasim|GEE1731045

To plot subplot from a set of data


close all;
clc;
data2= xlsread('data2.xlsx');
x=data2(:,1);
y=data2(:,2);
z=data2(:,3);
subplot(2,1,1);
plot(x,y);
subplot(2,1,2);
plot(x,z);

EXAMPLE-4
TABLE NO.-4
X Y Z
65 85 34
76 86 65
54 34 87
98 34 12
23 45 45
76 77 67
98 87 98
76 43 65
45 97 8
76 54 76
2D PLOT

100

80

60

40

20
20 30 40 50 60 70 80 90 100

100

50

0
20 30 40 50 60 70 80 90 100

FIGURE-2.4

Anda mungkin juga menyukai