how to read data from excel file
9 views (last 30 days)
Show older comments
Dear All,
I want to understand how to read the excel data from the following code. I am a beginer in matlab. I need your help in this regard.
% data for each model.
% data = csvread('data_JNP2014.csv',1) What does 1 means is it the first sheet
% x1 = data(:, [1 3 5]);what does this line means?
x2 = data(:, [2 3 5]);
x3 = data(:, [1 2 3 5]);
x4 = data(:, [1 3 4 5 6]);
x5 = data(:, [2 3 4 5 6]);
x6 = data(:, [1 2 3 4 5 6]);
0 Comments
Accepted Answer
David Hill
on 7 Oct 2021
I would use readmatrix
data=readmatrix('data_JNP2014.csv');%this reads the data from csv into 316x6 matrix
x1=data(:,[2 3 5]);%this forms a matrix (316x3) with columns 2,3,5.
More Answers (1)
Mathieu NOE
on 7 Oct 2021
hello
your csv file has one first row wit this header (name of 6 variables : lib,pc,ir_can,ir_us,un_can,un_us)
data = csvread('data_JNP2014.csv',1)
means we skip the first line (refer to the help / doc ) because we only want the numerical data that starts at row 2
M = csvread('FILENAME',R,C) reads data from the comma separated value formatted file starting at row R and column C. R and C are zero based so that R=0 and C=0 specifies the first value in the file.
now you have data which is an array of 316 lines (time axis is vertical) by 6 columns (cf the 6 variables names in the header line)
therefore data has size 316 x 6
if you create a new variable x1 with this command :
x1 = data(:, [1 3 5])
this means we keep all rows of data array but want to have only columns 1 , 3 and 5 extracted from data array
and of course size of x1 is 316 x 3
0 Comments
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!