MATLAB Answers


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.

Asked by David Rudolph on 7 Jun 2014
Latest activity Commented on by Image Analyst
on 14 Jun 2014

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!


Show 1 older comment

Let me rephrase the portion of the problem I am struggling with. How do I index an entire column of a matrix but only part of a row of that same matrix? For example, if I had matrix A = [ 1 3 5; 2 4 6] and matrix B = [0 0 0; 0 0 0], how would I index column 1 of matrix A to replace the first two elements of matrix B with those numbers?

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.

Log in to comment.

3 Answers

Answer by dpb
on 7 Jun 2014
Edited by dpb
on 8 Jun 2014

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


This will give nPerTrial columns.

As noted above, if


then you've got a problem that's insoluble w/o additional information.


Log in to comment.

Answer by Star Strider
on 10 Jun 2014

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)


B =
       1     0     0
       2     0     0


Log in to comment.

Answer by dpb
on 10 Jun 2014

...How do I index an entire column of a matrix but only part of a row of that same matrix?

Star's answer generalized...


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



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?


Log in to comment.

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today