Matrix indexing - Picking columns

조회 수: 12 (최근 30일)
bondpen
bondpen 2018년 4월 15일
댓글: Jan 2018년 4월 16일
So I trying to give an output a matrix which contains every fifth column of input (A). Below is what my current script look like.
function B = Script30( A )
B = A(:,1:5:end);
end
  댓글 수: 5
bondpen
bondpen 2018년 4월 15일
편집: bondpen 2018년 4월 15일
I just in habit in this naming scheme lmao.
It giving me rows instead of columns.
Jan
Jan 2018년 4월 16일
What give you rows? The shown code extracts columns.

댓글을 달려면 로그인하십시오.

채택된 답변

David Fletcher
David Fletcher 2018년 4월 15일
Do you mean this instead of your 1:5:end?
5:5:end
If you explicitly also want column 1 the you could use [1 5:5:end]
  댓글 수: 12
bondpen
bondpen 2018년 4월 15일
Yea, that does the trick. What is ":," for? Does it tell command to choose columns?
David Fletcher
David Fletcher 2018년 4월 15일
What the first colon? It means all rows and columns 5,10,15...etc. If you don't have the first colon - as you have found - it will compact all selected columns into one row. Well that was a bit harder than it should have been, I think I need a lie down.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by