1

I have data stored in variable data.

 data =  
    [43.98272955    39.55809471;            
    -49.51656799    28.57164726;
    -9.475861028    -44.31264255;
    27.14884251     2.603921223;
    -2.914496888    7.864022006;
    4.093025860     4.816211687;
    -12.11007479    5.797539648;
    -1.653535904    -12.49864642;
    5.978990391     1.229984916;
    0.9837133282    -2.001124423;
    5.674977844     6.323209942;
   -9.574459589     3.696791663;
    0.3410452503    -7.338955191]

but need use only data corresponding to multiple numbers of x. Example:

   if x = 3,

want store only multiple rows of 3, so

newdata = [-9.475861028 -44.31264255; 
4.093025860 4.816211687; 
5.978990391 1.229984916;
-9.574459589 3.696791663]

how do I do that?

P.S I would use the command textscan.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

3 Answers3

5

this is straightforward with indexing:

newData = data(3:3:end,:)
Jonas
  • 74,690
  • 10
  • 137
  • 177
1

If I understood the question correctly:

data(x:x:length(data),:)

Josh Greifer
  • 3,151
  • 24
  • 25
-1

You could just do just scan it row by row using the mod (modulo) function to extract rows corresponding to the desired multiples. For example:

x=3;
newdata=[];

for k=1:size(data,1)
  if mod(k,x)==0
    newdata=[newdata; data(k,:)];
  end
end
Stuart
  • 875
  • 6
  • 12