-1

Take for exapmle cell array A {1x100}. Each cell in A is an image Mx5000. e.g. A{1,1} is 420x5000, A{1,2} is 400x5000,.... A{1,100} is 700x5000.

when I concatenate all the cells vertically, I get a Nx5000 MATRIX B. After doing an operetion, the 5000 is reduced to 20. So, I have images Mx20

Now, how can I re-concatenate the new Nx20 MATRIX B into cell arrays of size initial cell arrays e.g. B{1,1} is 420x20, B{1,2} is 400x20,... B{1,100} is 700x20

Xio
  • 39
  • 6

1 Answers1

1

Let the variable vertSizes be a vector 1x100 containing the vertical size of all elements in A. The variable C will be the new cell containing all matrices from B. The following code should work for the job.

vertSizes = [0, vertSizes];
for i = 1 : length(vertSizes) - 1
   previousPos = sum(vertSizes(1:i));
   newPos = previousPos  + vertSizes(i+1);
   C{1,i} = B(previousPos+1:newPos, :)
end
DomDev
  • 540
  • 2
  • 12
  • Thanks, this works! now, how can I put n-1 of the cells of C in one matix and 1 in another matrix. i.e. if I have 10 cells in C, how can I concatenate vertically 9 first cells in a matrix and 1 left cell in another matrix. This process should be repeated for all the 10 cells. i.e. in each of 10 itarations a differet cell should be kept out and other 9 cells should be vertically concatenated. – Xio May 11 '16 at 00:36
  • To do that, you will have to use another loop "for j = 1:n", inside another loop "for k = 1:n". Inside both loops, you can have a condition "if j ~=k, then concatenate", else than skip the concatenation. – DomDev May 11 '16 at 03:00