Re-assigning numerical subjects IDs to string user IDs from experimental data

I'm at a very basic level so need basic answers!
The experimental data I have received has each subejct given a random string as their user id, eg.'2q348ihbfow9lehyr'
They each have multiple attempts at an experimental task.
I now want to re-number all the trials by each participant with a simple number (from 1 upto around 300) and can't work out how to do this.
i know this is very easy!

 Accepted Answer

The 1st and 3rd output of unique is what you want. e.g.:
%completely made up demo data. Using a table for neatness. It doesn't matter which form you data comes in
t = table({'2q348ihbfow9lehyr'; '1az3'; '8bq7'; '1az3'; '2q348ihbfow9lehyr'; '1az3'; '5edf'}, [1;10;2;3;5;20;0], 'VariableNames', {'subject', 'testresult'})
[subjects, ~, id] = unique(t.subject) %get a mapping between subject string and integer id
t.id = id %optionally add the id the table

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!