0

I have a cell called Object that contains 1x24 cells which all have 1 column but have the number of rows ranging from 14 to 16. Some cells, however, are empty. I would like to concatenate these cell into one single cell P with the dimension of 16 x 24. This is what I have tried:

for z=1:24
Summary.P{z}=cat(2,Object{1,z});
end

However, this gives me the error: Cell contents assignment to non-cell array object. Is this because I have the empty cells? Ideally, I'd like to get rid of the empty cells before concatenating.

Could anyone please help me?

Thanks!

P.S. If the different numbers of rows are an issue, I could just use the first 14 rows of each cell. This will make all the non-empty cells even in terms of the number of rows.

Daniel Heilper
  • 1,182
  • 2
  • 17
  • 34
A.Rainer
  • 719
  • 5
  • 16
  • If you are unsure what is causing the error, then take your code and put it in a script (or a function called *test*) and add the following line just before all the real code: **dbstop if error**. When you run the script or function, the debugger will stop at the line that is causing the error, and in your case, at the **z** that is generating that error. That may help you to understand how/why the error is being thrown. I'm not too clear on the "single cell P with the dimension 16x24", as the above code seems to be just updating **P{z}** which would mean that **P** is simply 1x24. – Geoff May 28 '14 at 02:56
  • What you could do is in the loop, check to see if it's the empty cell. If it is, then simply do an assignment rather than a concatenation. If it isn't empty, then concatenate. – rayryeng May 28 '14 at 04:21
  • Can you provide example of the Object cell? How it is defined? – Marcin May 28 '14 at 04:28

1 Answers1

0

The initial error is most likely that either Summary.P is initialized and not as a cell or that Object is not a cell. The error means that you tries to access a cell element in a non-cell type. Ohter than that, the lines you run will give you a clone of Object. Third, are you trying to create 1 cell with a 16x24 matrix inside, you need to make sure that the dimensions are consistent. If they are use

Summary.P = {cell2mat(Object)}
patrik
  • 4,506
  • 6
  • 24
  • 48