3

I have a cell array called d_O3 of size 3x15. Here's what the first row looks like:

    10x29 cell
    31x29 cell
    40x29 cell
    ...

I want to turn column one inside each cell into a column array and vertically concatenate them all together.

Here's what I've done so far:

years = 1999:2013; % The 15 columns
m = 1; % Row 1. I'd like to be able to run a loop for the other rows to do the same thing, but I haven't figured out how.
for y = 1:numel(years)
    data{y,1} = d_O3{m.y}(:,1);
end

This creates a 15x1 cell that looks like this inside: 31x1 cell 40x1 cell 42x1 cell ...

Inside each cell (i.e. inside 31x1), there's a column array of strings. But I want it to all concatenate together so it looks like:

06-029-0001-88101
06-073-0010-88101
...

In other words, I want to make vertically concatenate all the cells above.

I can do it by doing the following:

vertcat(data{1,1},data{2,1},...)

But that would mean typing out data{i,1} 15 times. What's an easier way?

SugaKookie
  • 780
  • 2
  • 17
  • 41

1 Answers1

1
vertcat(data{1:15,1})

or

vertcat(data{:,1})

It creates a comma separated list which is passed to vertcat.

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • 2
    You could also apply this method directly to the `d_03` cell array and grab the first column to get the same result. This way you don't need to go through that first `for` loop. – eigenchris Mar 19 '15 at 15:50