How to loop through a dataset and skip every other row?
9 次查看(过去 30 天)
显示 更早的评论
I have a dataset and would like to create a loop to skip every other row and get the data pertaining to that data. for example:
- A 1,2,3,4,5,6
- B 7,8,9,10,11,12
- C 13,14,15,16,17,18
I would like to write a for loop to get the data in rows A,C, E, G, etc.
0 个评论
回答(2 个)
Azzi Abdelmalek
2014-1-13
If M is your matrix
out=M(1:2:end,:)
10 个评论
José-Luis
2014-1-14
That's the variable name. What's the variable type? Most likely a cell array. You can find out by:
class(data9.Location)
José-Luis
2014-1-14
编辑:José-Luis
2014-1-14
If you indeed have a cell array of strings, this should work:
your_data = cellfun(@(x) x(3:end),data9.Location,'uniformoutput',false)
Please accept an answer if it helps you.
2 个评论
José-Luis
2014-1-14
That's a different question.
sort(your_data)
Please accept an answer if it helps you.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!