How to change a portion of cell array?

I have a large data set where I've put trials into a cell array. So each cell contains 1 trial and within that cell trial{1,1} there is specific information about the trial. The first column in trial{1,1} is time.
How do you access the first column for each cell?
In the end, I want to change the first column to have time start from 0. So I plan on doing time = time-1

 Accepted Answer

Guessing as to what the structure is, try this:
trial{1} = {(1:10).', rand(10,1), 'Information'};
FirstColumn = trial{1}{:,1}
SecondColumn = trial{1}{:,2}
ThirdElement = trial{1}{3}
producing (in this random run):
FirstColumn =
1
2
3
4
5
6
7
8
9
10
SecondColumn =
0.76396
0.8182
0.10022
0.17812
0.35963
0.056705
0.52189
0.33585
0.17567
0.20895
ThirdElement =
'Information'
.

6 Comments

My variable is a 79x1 cell
and then when I go into that variable, lets call it variable x
there are subarrays that are different sizes (y) but consistent in column (y, 7) double.
it's stimilar to your random generation of trial except that instead of a 1 x 1 cell, its a 79 x 1 cell that contains doubles instead of cells.
If you want help specifically with your data, post (upload) the data. Preferably, first save it as a .mat file.
Thank you! I've attached it here.
They all contain double arrays, so the addressing is straightforward.
To get Column 7 from each element in ‘trials’:
D = load('trials.mat');
trials = D.trials;
T01_C7 = trials{1}(:,7); % ‘trials’ #1, Column #7
T79_C7 = trials{79}(:,7); % ‘trials’ #79, Column #7
I just did it for the first and last cells here, however the rest would be straightforward. These only contain double arrays, not other information, so I assume those are in a different cell array.
As always, my pleasure!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!