This script use the matlab function readtable and table2array to read data from Excel file and plot the data.
Download the script read_xls.m
Data in Excel file:
Data in Excel file |
The script:
% This script read data from Excel file
% and put the data in array and plot the data
% Read the data from Excel file Book1.xlsx
% and put the data in table variable t.
disp( "The data read from Book1.xlsx file")
t = readtable("C:\Users\etmos\Desktop\Book1.xlsx")
% Put the data from table variable t to variable x, y.
% "x" and "y" are the titles of the data un xlsx file.
x = table2array(t(:, "x"));
y = table2array(t(:, "y"));
% plot thr data.
plot(x,y)
% and put the data in array and plot the data
% Read the data from Excel file Book1.xlsx
% and put the data in table variable t.
disp( "The data read from Book1.xlsx file")
t = readtable("C:\Users\etmos\Desktop\Book1.xlsx")
% Put the data from table variable t to variable x, y.
% "x" and "y" are the titles of the data un xlsx file.
x = table2array(t(:, "x"));
y = table2array(t(:, "y"));
% plot thr data.
plot(x,y)
Script Output
>> read_xls
The data read from Book1.xlsx file
t =
20×2 table
y x
___ __
1 1
4 2
9 3
16 4
25 5
36 6
49 7
64 8
81 9
100 10
121 11
144 12
169 13
196 14
225 15
256 16
289 17
324 18
361 19
400 20
The data read from Book1.xlsx file
t =
20×2 table
y x
___ __
1 1
4 2
9 3
16 4
25 5
36 6
49 7
64 8
81 9
100 10
121 11
144 12
169 13
196 14
225 15
256 16
289 17
324 18
361 19
400 20
Data Graph
No comments:
Post a Comment