-3

I have the following cell array:

<20x2>
<32x2>
<28x2>
<30x2>

What I am trying to do is read into row 1 of the cell array which is <20x2> and once I am in <20x2> I would like to apply the following function to the first column only.

In the first one I would like every row of column 1 in C{1,1} to be subtracted by 0.1. In the second one C{2,1} (<32x2>) I would like every row of column 1 to be subtracted by 0.2 and so on...

So to clarify I am trying to subtract n*0.1 from the first column of each submatrix in the cell array where n= row number of the cell array. So if there was a section in the cell array in row 8, column 1 would be subtracted by 8*0.1 = 0.8

I hope the question is clear enough, I have tried to word it as clear as I can.

Thanks in advance for any help/suggestions

Attempt

First = C{1,1}(:,1);
Subtraction = First - 0.1

Gives me my desired result but only for row 1 of my cell array.

Unique question to Applying function to vectors row by row because this involves a cell array as opposed to a matrix. The aspect of reading into a cell array makes it a different variant of the problem so if somebody was having a similar problem to this question the mentioned 'duplicate' question would not help, especially with little MATLAB knowledge like myself

Community
  • 1
  • 1
user3536870
  • 249
  • 1
  • 2
  • 13
  • 1
    Have you tried anything? Using loops perhaps? – Dan Sep 25 '15 at 07:09
  • I can do what I am asking if I just had a nx2 matrix but struggling to read into a cell array where n changes – user3536870 Sep 25 '15 at 07:11
  • You need to post some code to show that you have attempted to solve it yourself... why can you just go `...-n*0.1;...` where `n` is your `for`-loop variable? – Dan Sep 25 '15 at 07:16
  • Didn't include my attempt because it's a pretty pathetic effort. I have thought I need a loop. 1. I don't know how to apply the loop and 2. I really don't know how to call that n is changing so matlab reads through the entirety of my file – user3536870 Sep 25 '15 at 07:25
  • No, it's a different end goal :) – user3536870 Sep 25 '15 at 07:33

1 Answers1

1

It is very easy to adapt your attempt to a loop:

for n = 1:size(c,1)
    C{n,1}(:,1) = C{n,1}(:,1) - n*0.1;
end
Dan
  • 45,079
  • 17
  • 88
  • 157