필터 지우기
필터 지우기

How to loop through a dataset and skip every other row?

조회 수: 4 (최근 30일)
andrew
andrew 2014년 1월 13일
댓글: José-Luis 2014년 1월 14일
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.

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 13일
If M is your matrix
out=M(1:2:end,:)
  댓글 수: 10
andrew
andrew 2014년 1월 14일
they are stored in data9.Location
José-Luis
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
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
andrew
andrew 2014년 1월 14일
is there a way to sort the column so that all the A's, are together?
José-Luis
José-Luis 2014년 1월 14일
That's a different question.
sort(your_data)
Please accept an answer if it helps you.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by