Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

importing data from excel, finding the last row and inserting value in a matrix

Asked by John on 19 Dec 2011

Hi,

I'm importing data into Matlab from excel via the following command:

cycle=xlsread('E:\dc.xlsx','Sheet1')

I do not know the number of the last row of data.

But I need to create a 2D matrix 'grade' with zero-zero on the first row and the number of the last row of data in the excel sheet and 0 on the second row.

For example if the last row of data was on the 10th row then 'grade' would be:

grade = [0 0;10 0];

How would I do this if I do not know the number of the last row of data in advance?

May thanks

0 Comments

John

Tags

Products

No products are associated with this question.

2 Answers

Answer by Matt Tearle on 19 Dec 2011
Accepted answer

If you're already reading in the data, why not just query its size?

nrows = size(cycle,1);
grade = [0,0;nrows,0];

1 Comment

John on 19 Dec 2011

Many thanks Matt

Matt Tearle
Answer by Patrick Saegesser on 19 Dec 2011

did you try

size(cycle,1) 

size along dimension 1 (rows) will give you the length of your dataset, and assuming you don't have any NaN in your set, it is the number of the last row.

you can then assign any variable, e.g.

Last = size(cycle,1)
Grade = [0,0;Last,0]

and get your output.

1 Comment

John on 19 Dec 2011

many thanks

Patrick Saegesser

Contact us