How to extract matrix data based on another matrix

10 ビュー (過去 30 日間)
Alyna
Alyna 2014 年 12 月 6 日
編集済み: Star Strider 2014 年 12 月 7 日
I have a EMG data that is separated by markers. I created a separate matrix that puts 1 between the markers and 0 everywhere else. There are 14 markers, therefore 7 pieces of data I'm interested in. How can I now break up my EMG data matrix based on the secondary matrix indicating the start and stop times?

採用された回答

Star Strider
Star Strider 2014 年 12 月 6 日
I’m making some assumptions here, so we may have to iterate this if I didn’t guess correctly.
If you have a vector of 14 ones separated by zeros, you will need to use the find function to convert them into numeric indices to create my ‘Mrkr’ vector from them. (You will not need to use unique because I assume they are in order already.)
The reshape function works the same on row or column vectors, so the shape of your marker vector (row or column) will work regardless.
My ‘EMGcell’ array assumes the EMG segments are not the same length, so the cell array accommodates their varying lengths. [If you choose to run my code to see how it works, because I used a random number generator to create the markers and then searched for unique values (that also orders them), you may have to run this a couple times if the reshape function throws an error. This is normal and not a bug.]
The code:
EMG = 0.1*randn(100,1); % Created Data
Mrkr = unique(randi(100,14,1)); % Creted Markers
Lidx = reshape(Mrkr, 2, [])'; % Reshape To Make Addressing Easier
for k1 = 1:size(Lidx,1)
EMGcell(k1) = {EMG(Lidx(k1,1):Lidx(k1,2))}; % Extract EMG
end
If this does not correspond to your data, let me know. We can do your EMG segment extraction with some minor modifications of my code.
  2 件のコメント
Alyna
Alyna 2014 年 12 月 7 日
編集済み: Star Strider 2014 年 12 月 7 日
So I have 12 muscles with EMG data in one file that I need to perform analysis on. I have concatenated each muscle horizontally into a matrix - so each muscle has it's own column. The markers indicate where a rep starts and stops. I need to break up each set of EMG data into individual reps to then proceed with further evaluation.
I've used the following code to find the markers that were placed into the data via the EMG software. The code finds the points between the markers and makes that range 1 while everything else is 0. This code creates a 7 column matrix, each column holding the location of each repetition range.
time = (0:length_sec*sampRate - 1).'/sampRate;
num_spans = round(length(Markers)/2);
spans = zeros(length(time),num_spans); % Pre-allocate the size of the spans matrix
for i=1:num_spans
spans(:,i) = time > Markers(2*i-1) & time < Markers(2*i);
end
This is the 0 and 1 matrix I'm talking about that I now need to go back into the data and extract those locations.
I tried the code you gave me with my data, but MATLAB only pulled out 3-4 numbers from the data, which is incorrect. I'm trying to get it to work, but is this going to be successful instead of using the previously code I posted?
Thanks!
Star Strider
Star Strider 2014 年 12 月 7 日
編集済み: Star Strider 2014 年 12 月 7 日
My pleasure!
Doesn’t concatenating muscles require Board Certification in Orthopaedic surgery?!
My code (I didn’t have yours or even a sample of it so I had to make something up) assumes a vector of zeros the length of the entire EMG record, except for 1 where the markers are. I used the positions of the markers to create a vector of indices (using the find function) that demarcated your EMG ranges of interest.
Are your data different from what I imagined them to be?
I cannot follow your code because I have no context for the variables, or for that matter, for your data.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by