Determining the second last row

6 次查看(过去 30 天)
Hi there,
How would you code the number of rows minus one? Below I use size() to find the number of rows, but I want to set nrows to the number or rows minus 1.
Many thanks
sch_cycle=xlsread('C:\Autonomie practice\cycle.xls','Input_data');
nrows = size(sch_cycle,1);

采纳的回答

Jonathan Sullivan
Jonathan Sullivan 2012-3-16
sch_cycle=xlsread('C:\Autonomie practice\cycle.xls','Input_data');
nrows = size(sch_cycle,1)-1;

更多回答(1 个)

Dr. Seis
Dr. Seis 2012-3-16
If you mean you want to set "sch_cycle" to have nrows - 1, then no need to actually determine "nrows" beforehand (just use "end"):
sch_cycle = sch_cycle(1:end-1,:);
You can setup an "if" statement in order to make sure "nrows" is greater than 1.
  3 个评论
Dr. Seis
Dr. Seis 2012-3-16
Looks like "end" will still work there, too:
sch_cycle(1:max(1,end-1),:); % For all rows except last row
sch_cycle(max(1,end-1),:); % For just second to last row
John
John 2012-3-16
Thanks for all the suggestions guys.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by