How can I extract various trial data in Excel?
Show older comments
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
Walter Roberson
on 1 Sep 2017
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?
Marcus Marpoe
on 1 Sep 2017
Answers (1)
Walter Roberson
on 1 Sep 2017
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
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!