get specific range of data from vector, indicated by other vector
    7 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Marilena Wilding
 el 16 de Mzo. de 2021
  
    
    
    
    
    Comentada: Marilena Wilding
 el 16 de Mzo. de 2021
            I have a big datafile, containing several columns of data (data.d). I  need the data of the second column of data --> data.d(:, 2). The  first column of this file indicates the corresponding timestamps (i.e.  it says when the event of column two happened). Column two, however, is  huge and I only need a certain range numbers of it: i.e. I have an index list with timestamps (index) from another file which indicates, at what timepoint a button was pressed, so which range I need - from this  timestamp, I need to infer into data.d(:, 2) and go back 6000ms and get  all datapoints from -6000 to my original index from data.d (:, 2). Every row represents 2 ms, that's why I wrote -3000. Currently I am getting  the range of numbers between data.d(i,2) minus 3000 until data.d(i, 2)  in equal steps, which is not what I need at all. I need the values of my original data in data.d(:, 2). The second thing I am not sure about is how I can get not just the first range of elements (so the first range of -6000ms to 0) but all ranges  of these 5 indeces in 'index' in one vector. Thank you all very much in  advance!!
index = [13500, 14628, 18500, 20788, 24567]
for i = 1:length(data.d(:, 2))
    if ismember(i, index)
    loc_list = (data.d(i-3000,2) : data.d(i,2))'
    end
end 
0 comentarios
Respuesta aceptada
  Stephen23
      
      
 el 16 de Mzo. de 2021
        
      Editada: Stephen23
      
      
 el 16 de Mzo. de 2021
  
      X = [13500, 14628, 18500, 20788, 24567];
N = numel(X);
C = cell(1,N);
for k = 1:N
    Y = (X(k)-3000):X(k);
    C{k} = data.d(Y);
end
V = vertcat(C{:}) % or HORZCAT
Or
F = @(x)data.d((x-3000):x);
C = arrayfun(F, X, 'Uni',0);
V = vertcat(C{:}) % or HORZCAT
Más respuestas (0)
Ver también
Categorías
				Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

