Divide a dataset into subsets
古いコメントを表示
Hello everyone
I have a dataset named chan56 which is 1619936x1 and a vector called markers which is 1x202. The vector markers has the events of the dataset chan56 and i want to split chan56 into subets that contain -1200 indexes from each event until +300. I tried
Data = []
DataMatrix =[zeros(1,length(markers)*1500)];
for n =1 :length(chanPOz)
for i =1:length(markers)
if markers(i) == chanPOz(n)
T = chanPOz(n);
Data = chanPOz(n-1200:n+300);
DataMatrix = [DataMatrix DataMatrix+Data];
end
end
end
But i cant take the DataMatrix
5 件のコメント
Akira Agata
2018 年 1 月 31 日
I'm confused a little bit...
Could you provide a simple example ??
Jos (10584)
2018 年 1 月 31 日
I think you want to create a matrix with 202 rows (=number of markers). Each row contains the data from the chan56 around this marker.
What does an element in the vector markers represent? An index into chan56?
Greg Athanasiadis
2018 年 1 月 31 日
編集済み: Guillaume
2018 年 1 月 31 日
Jos (10584)
2018 年 1 月 31 日
I am a little confused by the if statement. Am I right to assume that each value of markers is a direct index into chanPOZ?
Greg Athanasiadis
2018 年 1 月 31 日
編集済み: Greg Athanasiadis
2018 年 1 月 31 日
採用された回答
その他の回答 (1 件)
Guillaume
2018 年 1 月 31 日
Even a single loop is not needed. A double loop is a complete waste of time.
Assuming R2016b or later,
assert(all(markers > 1200 & markers < numel(chanPoz) - 300), 'some markers too close to the edges');
indices_to_extract = markers(:) + (-1200:300); %create a matrix of indices
extracteddata = chanPoz(indices_to_extract.'); %extract relevant data as a matrix
Each column of extracteddata is the -1200 to 300 points around the corresponding marker. If you do want it as a vector (but why?) then you can then do:
extracteddata = reshape(extracteddata, 1, []);
If you're on a version earlier than R2016b, then the indices_to_extract line becomes
indices_to_extract = bsxfun(@plus, markers(:), -1200:300);
3 件のコメント
Jos (10584)
2018 年 1 月 31 日
+1 I still need to get used to the "new" expansion behaviour of + ...
Greg Athanasiadis
2018 年 1 月 31 日
I clearly wrote:
If you're on a version earlier than R2016b, then the indices_to_extract line becomes
indices_to_extract = bsxfun(@plus, markers(:), -1200:300);
カテゴリ
ヘルプ センター および File Exchange で Downloads についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!