How to extract matrix data based on another matrix
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alyna
el 6 de Dic. de 2014
Editada: Star Strider
el 7 de Dic. de 2014
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?
1 comentario
Image Analyst
el 6 de Dic. de 2014
Can you give a numerical example? http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
Respuesta aceptada
Star Strider
el 6 de Dic. de 2014
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 comentarios
Star Strider
el 7 de Dic. de 2014
Editada: Star Strider
el 7 de Dic. de 2014
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Spectral Measurements 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!