Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

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!

4 Comments

David Rudolph on 10 Jun 2014

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?

Star Strider on 10 Jun 2014

I decided to put my reply as an Answer ...

Image Analyst on 14 Jun 2014

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.

David Rudolph

Products

No products are associated with this question.

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

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.

0 Comments

dpb
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)

produces:

B =
       1     0     0
       2     0     0

0 Comments

Star Strider
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...

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?

0 Comments

dpb

Contact us