Reputation: 29
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.
Upvotes: 0
Views: 44
Reputation: 12214
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.
Upvotes: 1