필터 지우기
필터 지우기

Determining the second last row

조회 수: 5 (최근 30일)
John
John 2012년 3월 16일
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에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by