I have 10 sets of EMG data stored in 3605 X 1 matrices. I am trying to write a program to sort the raw data by type and number of trials and replace the data into a separate matrix. I can't figure out how to replace the rows to the right dimensions.

조회 수: 1 (최근 30일)
Here is my code thus far:
function [ outData ] = splitTrial( rawData, numTrial ) %SPLITTRIAL Summary of this function goes here % Detailed explanation goes here
numRows = round(length(rawData)/(numTrial)); outData = zeros(numRows, numTrial); for i = 1:numTrial
outData(:,i) = rawData(1,:);
end end
rawData represents loaded EMG data with 3605 elements ( 3605 X 1 matrix). The number of columns for outData is simply the number of trials. I can't, however, come up with a general algorithm to replace column wise the elements from the raw data into outdate with the proper matrix dimensions specified in the above reallocated matrix. Any help would be greatly appreciated!
  댓글 수: 4
Image Analyst
Image Analyst 2014년 6월 14일
So David, which one of these fine answers are you officially going to "Accept". Note that you can "Accept" only one but you can vote for all of them, not just the one that you accept. If there's no answer yet, then explain what the current problem is.

댓글을 달려면 로그인하십시오.

답변 (3개)

dpb
dpb 2014년 6월 7일
편집: dpb 2014년 6월 8일
Also format the code you do have so it's legible...if it doesn't look right in the preview window the posting isn't ready for prime time.
It would seem that if the number of trials is evenly divisible into the length of the vector (and if it's not, you need another variable vector to indicate the length of each trial) that the output rearranged would simply be
nPerTrial=length(rawdata)/numtrials);
outdata=reshape(rawdata,nPerTrial,[]);
This will give nPerTrial columns.
As noted above, if
mod(length(rawdata),numtrials)~=0
then you've got a problem that's insoluble w/o additional information.

Star Strider
Star Strider 2014년 6월 10일
Is this what you want?
A = [ 1 3 5; 2 4 6];
B = [0 0 0; 0 0 0];
B(1:2,1) = A(1:2,1)
produces:
B =
1 0 0
2 0 0

dpb
dpb 2014년 6월 10일
...How do I index an entire column of a matrix but only part of a row of that same matrix?
Star's answer generalized...
A(r1:r2,col)
is the submatrix from row r1 thru r2 for the column col. Write an address expression of any sort for the assignment that is of commensurate size in each dimension for the target.
The above can be expanded to include a specific delta rather than the default unitary step as
A(r1:step:r2,col)
See
doc colon
and the "Getting Started" documentation for details.
I wonder again, though, regarding the original problem that raised the question if there isn't a more expeditious solution if you'd define the actual data structure more fully. Is there an issue in an erroneous assumption in my previous answer?

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by