Matrix indexing - Picking columns

3 次查看(过去 30 天)
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 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by