0

I am running an experiment where I have 5 different conditions and participants gives a response from 0-9 on each trial. As a result of running the experiment I get two cell arrays - one containing the conditions of each trial and one containing the participants response for that trial. For example this (for 10 trials, 2 for each condition):

condition =

 2     1     4     4     2     5     3     1     3     5


ratings =

 4     2     8     7     4     9     5     1     3     8

I would like to run a regression and therefore I wish to convert the condition to a value that actually represents the independent variable, which is distance between two images (in pixels).

level 1 = 580 pixels, 2=480, 3=380, 4=280, 5=180

I'm sorry if this is a very obvious question, but how can I easily create a new cell array - 'distance in pixels' - from my 'condition' cell array? I am very new to MATLAB and programming so sorry if i'm missed out anything important, i will try and edit this question as much as i can in response to suggestions. I am running MATLAB with psychtoolbox on windows.

Emily
  • 29
  • 1
  • 7
  • 2
    `B = 680 - condition.*100;` Why are you using cell arrays? – sco1 Jun 21 '16 at 17:45
  • thank you so much! I'm not entirely sure. I am planning no running a regression, and I was under the impression that I should do that using cell arrays, but I could very well be wrong! – Emily Jun 21 '16 at 17:48
  • If you can avoid using cell arrays, then do so. Besides which, regression is a very **numeric** centric operation, so don't use cell arrays at all.... in fact, NEVER for regression. – rayryeng Jun 21 '16 at 17:59
  • thanks @rayryeng for the advice! I will try and find another way – Emily Jun 21 '16 at 18:01

1 Answers1

1

There are a couple approaches.

First, you could use the mathematical relation:

condition = [2, 1, 4, 4, 2, 5, 3, 1, 3, 5];
B = 680 - condition.*100

Which returns:

B =

   480   580   280   280   480   180   380   580   380   180

Second, you could utilize MATLAB's linear indexing to make a lookup table:

condition = [2, 1, 4, 4, 2, 5, 3, 1, 3, 5];
level = [580, 480, 380, 280, 180];
B2 = level(condition)

Which returns:

B2 =

   480   580   280   280   480   180   380   580   380   180

I've written these without using cell arrays, but you can utilize cell2mat and num2cell/mat2cell where needed if you must use cell arrays for some reason.

sco1
  • 12,154
  • 5
  • 26
  • 48