How can I extract various trial data in Excel?

I have an Excel spreadsheet that is 38905x10. The rows are made up of data collected from different trials. For example the first trial has 2000 data points so it would be a 2000x10. I want to extract each trial from the spreadsheet with the use a loop in MATLAB. The first column is labeled Data Points and starts at 1 and goes until the trial is over. However, the trials are not always equal in length so I can't write a code that splits the data into 10, 2000x10 matrices.
This is what I had in mind, but just can't figure it out. So I know the data points column will eventually start at 1 again and this indicates a new trial. What I mean by that is, data points for trial 1 could be 1-2000, then in row "2001" the column would start back over at 1. I thought about making some sort of counter that looked at this column. So if "n" is the number in the Data Point column I wanted to create a matrix each time n>n+1. This means that at row 2000, n=2000 and in row 2001, n=1. Then n would be greater than n+1, 2000>1. Can anyone offer some advice?

2 Comments

When you look at the data, how can you tell where the beginning of a trial is? Is there separate information about how long each trial is?
I can tell where each trial starts using the first column which is Data Points. Each trial will run for a certain amount of points (not always the same interval). So for example. trial one has 2000 data points and goes from TABLE row 1-2000. Then trial two starts at TABLE row 2001 with a data point value of 1 and goes for a certain length.

Sign in to comment.

Answers (1)

x = xlsread('YourDataFile.xls');
trial_boundaries = [find(x(:,1) == 1); size(x,1)+1];
trial_lengths = diff(trial_boundaries);
split_trials = mat2cell(x, trial_lengths, size(x,2));
num_trials = length(split_trials);
for K = 1 : num_trials
this_trial = split_trials{K};
... do something with this trial
end

Asked:

on 1 Sep 2017

Answered:

on 1 Sep 2017

Community Treasure Hunt

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

Start Hunting!